closestWithClass function
This element or the closest of its ancestor with the given class.
Implementation
Element? closestWithClass(Element? target, String className) {
while (target != null) {
if (target.attributes.containsKey("class") &&
target.classes.contains(className)) {
return target;
}
target = target.parent;
}
return null;
}