Javascript examples for jQuery Selector:parent child
The ("parent > child") selector selects all elements that are a direct child of the parent element.
Parameter | Description |
---|---|
parent | Required. the parent element |
child | Required. direct child element |
The following code shows how to select all <span> elements that are a direct child of a <div> 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 w w w.j av a2s.c om*/ </script> </head> <body> <ul class="test"> <li>List item</li> <li>List item <ul> <li>Nested list item (will not have border)</li> </ul> </li> <li>List item</li> </ul> </body> </html>