For each element in the set, get the first element that matches the selector by testing the element itself and traversing up through its ancestors.
// <form><div><input></div></form>
$('input').closest('form').addClass('found');
<form class="found">...</form>
// <div class="active"></div>
$('div.active').closest('.active');
// Returns the div itself
<div class="active"></div>
| Parameter | Type | Description |
|---|---|---|
| selector | string | element | SR | A string selector, DOM element, or SR object to match against. |
Returns: A new SR object.