Skip to content
Related Articles

Related Articles

jQuery parent descendant Selector

Improve Article
Save Article
  • Last Updated : 14 Nov, 2022
Improve Article
Save Article

jQuery parent descendant Selector selects every element which are descendant to a specific(parent) element. 

Syntax: 

$("parent descendant")

Example 1:  

html




<!DOCTYPE html>
<html>
<head>
    <script src=
  </script>
  <script>
        $(document).ready(function() {
            $("div span").css("color",
                              "lightgreen");
        });
    </script>
</head>
<body>
    <h4>This div element has descendant span:</h4>
    <div>
        <span>DESCENDANT ELEMENT</span>
    </div>
</body>
</html>


Output: 

Example 2:

HTML




<!DOCTYPE html>
<html>
<head>
  <script src=
  </script>
  <script>
    $(document).ready(function () {
      $("button").click(function () {
        $("div span").css("color", "lightgreen");
      });
    });
  </script>
</head>
<body>
  <h4>This div element has descendant span:</h4>
  <div>
    <span>DESCENDANT ELEMENT</span>
  </div>
  <br>
  <button>Change color</button>
</body>
</html>


Output:

 


My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!