In jQuery, Query Traversing refers to the process of navigating and manipulating the Document Object Model (DOM) to select and work with specific elements on a web page. The Descendants method is a way to select all elements that are descendants of a given parent element, regardless of their level in the DOM hierarchy. The specific method you are referring to is likely the children() method, not the descendants method.
The children() method in jQuery is used to get the immediate children of each element in the set of matched elements. It only travels a single level down the DOM tree.
Syntax
$(selector).children(filter)
selector : A string containing a selector expression to match the children against.
filter : A string containing a filter expression to narrow down the selection of children.
<html> <head> <title>DOM Query</title> <style> li{color:black;} </style> </head> <body> <h3>Children</h3> <ul class='list'> <li>Graphic Designing</li> <li>Web Designing</li> <li>Programming</li> <li> <ul> <li>C Program</li> <li>C++ Program</li> <li>Java</li> <li>C#</li> </ul> </li> </ul> <script src="js/jquery.js"></script> <script> $("document").ready(function(){ $('ul.list').children('li').css('color','green'); }); </script> </body> </html>
Remember that jQuery simplifies DOM manipulation and traversal, making it easier to work with HTML documents in a more concise manner.
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions