jQuery children( [selector] ) Method

« Previous Chapter Next Chapter »

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:

Example

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:

Example

<html>
<head>
   <script type="text/javascript"  src="../../js/jquery-2.2.0.js"></script>
 <script>
  $(document).ready(function(){
     $("div").children(".selected").addClass("blue");
  });
  </script>
  <style>
  .blue { color:blue; }
  </style>
</head>
<body>
  <div>
    <span>NewFile.</span>
    <p class="selected">NewFile. 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.

Example

<html>
<head>
   <script type="text/javascript"  src="../../js/jquery-2.2.0.js"></script>
 <script>
  $(document).ready(function(){
     $("div").children(".selected").addClass("blue");
  });
  </script>
  <style>
  .blue { color:blue; }
  </style>
</head>
<body>
  <div>
    <span>NewFile.</span>
    <p class="blue">NewFile. Again</p>
    <div class="blue">And Again</div>
    <p class="biggest">And One Last Time</p>
  </div>
</body>
</html>
                                        
Code It Online

« Previous Chapter Next Chapter »

Have Any Suggestion? We Are Waiting To Hear from YOU!

Your Query was successfully sent!