menu

jQuery closest Method


jQuery closest Method :It is used to get first ancestor element of the current selection. If you want to get first ancestor element of the selected element use closest method which accepts filter as input parameter.


Syntax of jQuery closest Method

Here is syntax for closest Method example in jQuery –

filter String containing the selector expression for matching the elements.

jQuery Traversing – closest Example

jQuery closest() Method – Example

Try it ยป

The above code will produce following result-

Note : This is image of the output. To run this demo click on the above “Try it” button.

jQuery closest Method