I am trying to figure out a way to carry out something similar to jquery's nearest function. Ex:
$("a.test").nearest(".group-parent");
but in dart.
I was looking through the HtmlElement class to see if there was a way i could do as above but have not found anything really which would walk up the tree until it found the selector (or null, etc).
Is there something in place that can already be leveraged to do such a thing?
I was thinking to just create a function which will loop through the parents until parents = null (or whatever returns for the document).
HtmlElement findNearestClass(HtmlElement node, String classString){
if (node == null) return null;
if (node.classes.contains(classString)) return node;
return findNearestClass(node.parent, classString);
}
.closest()
?Element closest(String selector);