How to locate all the descendant elements of a particular type of element?


The find( selector ) method can be used to locate all the descendant elements of a particular type of elements. The selector can be written using any selector syntax.

Example

You can try to run the following code to learn how to locate all the descendant elements of a particular type of elements:

Live Demo

<html>

   <head>
      <title>jQuery Example</title>
      <script src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
       
      <script>
         $(document).ready(function() {
            $("p").find("span").addClass("selected");
         });
      </script>
       
      <style>
         .selected {
           color:blue;
         }
      </style>
   </head>
   
   <body>
      <p>This is first paragraph and <span>THIS IS BLUE</span></p>
      <p>This is second paragraph and <span>THIS IS ALSO BLUE</span></p>
   </body>
   
</html>

Updated on: 09-Dec-2019

58 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements