Is there an efficient way to check if a given element matches a selector like the is()-method in jQuery (http://api.jquery.com/is/)?
I have found this solution, but I think it has bad performance:
public static String cleanSelector(String selector) {
return selector.replaceAll(":link|:active|:visited|:hover|:after|:focus", "");
}
public static boolean elementIs(Element elem, String selector, Element root) {
Elements elems = root.select(cleanSelector(selector));
return elems.contains(elem);
}