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

jQueryWeb DevelopmentFront End Technology

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>
raja
Published on 16-Dec-2017 11:31:45
Advertisements