jQuery prevAll( [selector] ) Method

« Previous Chapter Next Chapter »

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:

Example

selector.prevAll( [selector] )
                                        

Parameters:

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

  • selector: This is optional selector to filter the previous Elements with.

Example:

Example

<html>
<head>
   <script type="text/javascript"  src="../../js/jquery-2.2.0.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.

Example

<html>
<head>
   <script type="text/javascript"  src="../../js/jquery-2.2.0.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>
                                        
Code It Online

« Previous Chapter Next Chapter »

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

Your Query was successfully sent!