Back

.closest( selector, [context] )

Find the closest ancestor that matches a given selector

For each selected element, get the first element that matches the selector by testing the element itself and traversing up through its ancestors in the DOM tree

Params

selector{Selector}A selector expression to match elements against
context{Context} [optional]The context to use while searching for matches

Returns

DollarJS (new set)

Examples

$('p').closest('.outer')