java - Is there an efficient way to test if an element matches a selector in Jsoup? -


is there efficient way check if given element matches selector is()-method in jquery (http://api.jquery.com/is/)?

i have found solution, think 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); } 

using package-private queryparser class:

evaluator eval = queryparser.parse(query); boolean result = eval.matches(element.ownerdocument(), element); 

Comments