Copyright © tutorialspoint.com

jQuery - next( [selector] ) Method

previous next


Advertisements

Description:

The next( [selector] ) method gets a set of elements containing the unique next siblings of each of the given set of elements.

Syntax:

Here is the simple syntax to use this method:

selector.next( [selector] )

Parameters:

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

Example:

Following is a simple example a simple showing the usage of this method. Try this example without passing selector in next() 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").next(".selected").addClass("hilight");
     });

  </script>
  <style>
      .hilight { background:yellow; }
  </style>

</head>
<body>
  <p>Hello</p>
  <p class="selected">Hello Again</p>
  <div><span>And Again</span></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").next(".selected").addClass("hilight");
     });

  </script>
  <style>
      .hilight { background:yellow; }
  </style>

</head>
<body>
  <p>Hello</p>
  <p class="hilight">Hello Again</p>
  <div><span>And Again</span></div>
</body>
</html>

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


previous next

Copyright © tutorialspoint.com