jQuery Traversing Descendants
A descendant is a child, grandchild, great-grandchild, and so on in logical connections. jQuery includes handy methods like as children() and find() for traversing down in the DOM tree at single or several levels to easily locate or obtain the child or other descendants of an element in the hierarchy.
jQuery children() Method
To access the direct children of the specified element, use the jQuery children() function. The following example uses the class to highlight the immediate children of the
<ul> element, which is
<li>. highlight on document ready.
jQuery find() Method
The descendent elements of the chosen element are obtained using the jQuery find() function. The find() and children() methods are similar in that they both search across numerous layers of the DOM tree to identify the latest descendant, but the children() function only searches a single level. The example below will place a border around all the
<li> elements that are descendants of the
If you wish to access all the descendant elements, though, you may use the universal selector.