Tutorials Point


  jQuery Tutorial
  jQuery UI
  jQuery References
  jQuery Resources
  Selected Reading

Copyright © 2014 by tutorialspoint



  Home     References     Discussion Forums     About TP  

jQuery - find( selector ) Method


previous next AddThis Social Bookmark Button


Advertisements

Description:

The find( selector ) method searches for descendent elements that match the specified selector.

Syntax:

Here is the simple syntax to use this method:

selector.find( selector )

Parameters:

Here is the description of all the parameters used by this method:

  • selector: The selector can be written using CSS 1-3 selector syntax.

Example:

Following is a simple example a simple showing the usage of this method.

<html>
<head>
<title>the title</title>
   <script type="text/javascript" 
   src="/jquery/jquery-1.3.2.min.js"></script>
   <script type="text/javascript" language="javascript">
   
   $(document).ready(function() {
      $("p").find("span").addClass("selected");
   });

   </script>
   <style>
      .selected { color:red; }
  </style>
</head>
<body>
   <div>
      <p><span>Hello</span>, how are you?</p>
      <p>Me? I'm <span>good</span>.</p>
   </div>
</body>
</html>

This would generate following result.

<html>
<head>
<title>the title</title>
   <script type="text/javascript" 
   src="/jquery/jquery-1.3.2.min.js"></script>
   <script type="text/javascript" language="javascript">
   
   $(document).ready(function() {
      $("p").find("span").addClass("selected");
   });

   </script>
   <style>
      .selected { color:red; }
  </style>
</head>
<body>
   <div>
      <p><span class="selected">Hello</span>, how are you?</p>
      <p>Me? I'm <span class="selected">good</span>.</p>
   </div>
</body>
</html>

To understand it in better way you can Try it yourself.



previous next Printer Friendly

Advertisements


  

Advertisements