Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

jQuery parent descendant Selector

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like 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
Last Updated : 14 Nov, 2022
Like Article
Save Article
Similar Reads
Related Tutorials