closest

fun <T : HTMLElement> closest(selector: HtmlTagName<T>): T?(source)

The closest() method of the Element interface traverses the element and its parents (heading toward the document root) until it finds a node that matches the specified CSS selector.

MDN Reference


fun <T : SVGElement> closest(selector: SvgTagName<T>): T?(source)
fun <T : MathMLElement> closest(selector: MathMLTagName<T>): T?(source)
fun closest(selector: String): Element?(source)