THE WORLD'S LARGEST WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

jQuery Traversing - Descendants


A relative is a youngster, grandkid, incredible grandkid, thus on.

With jQuery you can navigate down the DOM tree to discover relatives of an element.


Traversing Down the DOM Tree

Two valuable jQuery strategies for crossing down the DOM tree are:

  • children()
  • find()

jQuery youngsters() Method

The kids() technique restores every single direct offspring of the chose element.

This technique just navigate a solitary dimension down the DOM tree.

The following precedent returns all components that are immediate offspring of each <div> elements:

Example

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

You can likewise utilize a discretionary parameter to channel the look for children.

The following model returns all <p> components with the class name "first", that are immediate offspring of <div>:

Example

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

jQuery discover() Method

The discover() strategy returns relative components of the chose component, all the path down to the last descendant.

The following precedent returns all <span> components that are relatives of <div>:

Example

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

The following precedent returns all relatives of <div>:

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.