THE WORLD'S LARGEST WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

jQuery Traversing - Descendants

Descendants are children, grandchildren, great-grandchildren, and more.

With jQuery, you can traverse down the DOM tree to find descendants of an element.


Walk down the DOM tree

Here are two jQuery methods to traverse down the DOM tree:

  • children ()
  • find ()

jQuery children () method

The

children () method returns all immediate children of the selected element.

This method only traverses the DOM tree one level down.

The following example returns each <div> All immediate children of the element:

Example

$(document).ready(function(){
    $("div").children();
});
Try it yourself »

You can also use optional parameters to filter searches for child elements.

The following example returns all classes with the name "1" <p> Elements and they are <div> Immediate children:

Example

$(document).ready(function(){
    $("div").children("p.first");
});
Try it yourself »

jQuery find () method

The

find () method returns the descendant elements of the selected element, all the way down to the last descendant.

The following example returns <div> All offspring <span> element:

Example

$(document).ready(function(){
    $("div").find("span");
});
Try it yourself »

The following example returns <div> All descendants of:

Example

$(document).ready(function(){
    $("div").find("*");
});
Try it yourself »

jQuery Traversing Reference

For a complete overview of all jQuery Traversing methods, please go to our jQuery Traversing Reference.