Javascript examples for jQuery Selector:parent descendant
The ("parent descendant") selector selects all elements that are descendants of a specified element, which could be a child, grandchild, great-grandchild, etc, of that element.
Parameter | Description |
---|---|
parent | Required. parent element |
descendant | Required. the descendant element |
The following code shows how to select all <li> elements that are descendants of a <UL class='test'> element:
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("ul.test li").css("border", "4px double"); });/*from ww w . ja v a2s .c om*/ </script> </head> <body> <ul class="test"> <li>List item</li> <li>List item <ul> <li>Nested list item</li> </ul> </li> <li>List item</li> </ul> </body> </html>