closestWithClass function

Element? closestWithClass(
  1. Element? target,
  2. String className
)

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;
}