parent descendant Selector - Javascript jQuery Selector

Javascript examples for jQuery Selector:parent descendant

Description

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.

ParameterDescription
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:

Demo Code

ResultView the demo in separate window

<!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>

Related Tutorials