Tutorials Point


  jQuery Tutorial
  jQuery UI
  jQuery References
  jQuery Resources
  Selected Reading

Copyright © 2014 by tutorialspoint



  Home     References     Discussion Forums     About TP  

jQuery - children( [selector] ) Method


previous next AddThis Social Bookmark Button


Advertisements

Description:

The children( [selector] ) method gets a set of elements containing all of the unique immediate children of each of the matched set of elements.

Syntax:

Here is the simple syntax to use this method:

selector.children( [selector] )

Parameters:

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

  • selector: This is an optional argument to filter out all the childers. If not supplied then all the childerns are selected.

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>
  $(document).ready(function(){

     $("div").children(".selected").addClass("blue");

  });
  </script>
  <style>
  .blue { color:blue; }
  </style>
</head>
<body>
  <div>
    <span>Hello</span>
    <p class="selected">Hello Again</p>
    <div class="selected">And Again</div>
    <p class="biggest">And One Last Time</p>
  </div>
</body>
</html>

This would generate following result. This would apply blue color to all children with a class "selected" of each div.

<html>
<head>
<title>the title</title>
   <script type="text/javascript" 
   src="/jquery/jquery-1.3.2.min.js"></script>
 <script>
  $(document).ready(function(){

     $("div").children(".selected").addClass("blue");

  });
  </script>
  <style>
  .blue { color:blue; }
  </style>
</head>
<body>
  <div>
    <span>Hello</span>
    <p class="blue">Hello Again</p>
    <div class="blue">And Again</div>
    <p class="biggest">And One Last Time</p>
  </div>
</body>
</html>

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



previous next Printer Friendly

Advertisements


  

Advertisements