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-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">
              $( "#parentsUntilExample" ).on( "click", function(event) {             
                 $("p").parentsUntil("ul").css("border","1px solid green");

Try it »

The above example will produce the following output as below –

jQuery parentsUntil Method Example Demo


Add Comment

📖 Read More