jQuery parentsUntil Method


jQuery parentsUntil Method – jQuery “parentsUntil() Method ” is used to get all ancestors between selector and selector-element ie. stop point where to stop matching ancestor elements.

This method becomes useful when you are traversing the element in DOM. We are going to explain this method will full example and demo.


jQuery parentsUntil() method

Here is syntax for parentsUntil Method –

$(selector).parentsUntil(selector-element,filter);

selector-element It is stop point where to stop matching ancestor elements
filter : It is optional, A selector expression used to match(parent) the elements against.

jQuery parentsUntil Method Example

Here is an example with demo try it to test the functionality of the parentsUntil method-

jQuery parentsUntil() Method – Example

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

Try it »

The above example will produce the following output as below –

jQuery parentsUntil Method Example Demo


Advertisements

Add Comment

📖 Read More