jQuery prev method


jQuery “prev() Method ” is used to get previous elements of the selected element.


Syntax : jQuery prev() method

$(selector).prev(filter);

filter : It is optional, A selector expression used to match the elements against.

jQuery prev Method Example with syntax

jQuery prev() Method – Example 1

<script type="text/javascript">
         $(document).ready(function(){ 
              $( "#prevExample" ).on( "click", function(event) {             
                 $(".fourth").prev().css("border","1px solid green");
              });
               
          });
</script>

Try it »

jQuery prev Method Example with syntax

jQuery prev() Method – Example 2

<script type="text/javascript">
         $(document).ready(function(){ 
              $( "#prevExample" ).on( "click", function(event) {             
                 $("p").prev(".para2").css("border","1px solid green");
              });
               
          });
</script>

Try it »


Advertisements

Add Comment

📖 Read More