jQuery Intro

jQuery Intro Quiz

jQuery Intro Exercise

jQuery Basic

jQuery Basic Quiz

jQuery Basic Exercise

jQuery Advance

jQuery Advance Quiz

jQuery Advance Exercise

jQuery Selectors

jQuery Effects

jQuery Events

jQuery Methods and Properties

jQuery Traversing

jQuery CSS and HTML Methods

jQuery closest() Method

jQuery closest() Method



The closest() method is used to return the first ancestor of the selected element. An ancestor can be a parent, grandparent, great-grandparent, and so on. In this method, traversing happens upwards from the current element. It is similar to parents() method.


Some of its properties are:-


  1. It begins with the current element
  2. Travels up the DOM tree and returns the first ancestor that matches the passed expression
  3. The returned object contains zero or one element




Its syntax is:- $(selector).closest(filter, context)


Further Explanation:-


Parameter Description
filter Required. Specifies a selector expression, element, or jQuery object.
context Optional. An element within which a matching element may be found

Code Explanation

All Tutorials related to jQuery Traversing

All Sections related to jQuery