HTML tutorial
CSS3 tutorial
Bootstrap tutorial
JavaScript tutorial
JQuery tutorial
AngularJS tutorial
React tutorial
NodeJS tutorial
PHP tutorial
Python tutorial
Python3 tutorial
Django tutorial
Linux tutorial
Docker tutorial
Ruby tutorial
Java tutorial
C tutorial
C ++ tutorial
Perl tutorial
JSP tutorial
Lua tutorial
Scala tutorial
Go tutorial
ASP.NET tutorial
C # tutorial
jQuery Traversing Methods : Return the first ancestor of <span>, that is an <ul> element
The closest() method returns the first ancestor of the selected element.
An ancestor is a parent, grandparent, great-grandparent, and so on.
This method is similar to parents(), in that they both traverse up the DOM tree. The differences are as follows:
Return the first ancestor of the selected element:
Return the first ancestor using a DOM context to look up the DOM tree within:
Parameter | Description |
---|---|
filter | Required. Specifies a selector expression, element or jQuery object to narrow down the ancestor search |
context | Optional. A DOM element within which a matching element may be found |