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
With jQuery you can traverse down the DOM tree to find descendants of an element.A descendant is a child, grandchild, great-grandchild, and so on
Two useful jQuery methods for traversing down the DOM tree are:
children()
find()
The children()
method returns all direct children of the selected element.
This method only traverses a single level down the DOM tree.
The following example returns all elements that are direct children of each <div>
elements:
$(document).ready(function(){
$("div").children();
});
You can also use an optional parameter to filter the search for children.
The following example returns all <p>
elements with the class name "first", that
are direct children of <div>
:
$(document).ready(function(){
$("div").children("p.first");
});
The find()
method returns descendant elements of the selected element, all
the way down to the last descendant.
The following example returns all <span>
elements that are
descendants of <div>
:
$(document).ready(function(){
$("div").find("span");
});
The following example returns all
descendants of <div>
:
$(document).ready(function(){
$("div").find("*");
});
Use a jQuery method to get all direct children of a <div> element element.
$("div").();
For a complete overview of all jQuery Traversing methods, please go to our jQuery Traversing Reference.