jQuery closeest () selects the first parent element (by its HTML tag) of the selector or the selector itself (if it matches). For example, if you select the element "p" ($ ("p # someid")), it will begin to search from your element "p", and if there is no match, it moves to it parent. And so on
HTML example:
<div id='select_me'>Div <p id='id'>paragraph</p> </div>
$ ('# id'). closeest ('div) // will select the div # select_me as the closest parent div
where as
<p id='select_me'>Div <p id='select_me_now'>paragraph</p> </p>
$ ('# select_me_now') nearest (p); // select p # select_me_now
Maxim Ershov
source share