parent > child Selector - Javascript jQuery Selector

Javascript examples for jQuery Selector:parent child

Description

The ("parent > child") selector selects all elements that are a direct child of the parent element.

Syntax

Parameter Description
parentRequired. 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:

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

Related Tutorials