jQuery parents Method


jQuery “parents() Method ” is used to get all ancestors of the selected element.


Syntax : jQuery parents() method

$(selector).parents(filter);

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

jQuery parents Method Example

jQuery parents() Method Example

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

Try it »


Advertisements

Add Comment

📖 Read More