Copyright © tutorialspoint.com

jQuery - prevAll( [selector] ) Method

previous next


Advertisements

Description:

The prevAll( [selector] ) method finds all sibling elements in front of the current element.

Syntax:

Here is the simple syntax to use this method:

selector.prevAll( [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:

<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(){
       $("div:last").prevAll().addClass("hilight");
     });

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

</head>
<body>
   <div>first</div>
   <div>sibling<div>child</div></div>
   <div>sibling</div>
   <div>sibling</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(){
       $("div:last").prevAll().addClass("hilight");
     });

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

</head>
<body>
   <div class="hilight">first</div>
   <div class="hilight">sibling<div>child</div></div>
   <div class="hilight">sibling</div>
   <div>sibling</div>
</body>
</html>

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


previous next

Copyright © tutorialspoint.com