Loading Please Wait...

Logo Lynxsia IT Solutions

jQuery Traversing - Descendants

JQ DOM Traversing - Descendants

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.

Traversing Down the DOM Tree

Two useful jQuery methods for traversing down the DOM tree are:

  • children()
  • find()
jQuery children() Method

The jQuery 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");
          });
        
      
jQuery find() Method

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

This method only traverses a single level down the DOM tree.

The following example returns all <span> elements 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("*");
          });
        
      

How you feel about this blog:

Share this blog on:

Report Us

If you find any error in the turtorials, or want to share your suggestion/feedback, feel free to send us email at: info@lynxsia.com

Contact Us
Ads
Logo
Lynxsia IT Solutions

We are concern with various development process like website design & development, E-commerce development, Software development, Application development, SMS & Bulk SMS Provider, PWA Development, and many more..

Kotwali Road, Chhiptehri, Banda, 210001, UP, India

Copyright © 2022, Lynxsia IT Solutions, All rights reserved