jQuery parentsUntil() with Example

jQueryWeb DevelopmentFront End Technology

The parentsUntil() method in jQuery is used to return all ancestor elements between the selector and stop parameter value.


The syntax is as follows −


Above, the stop parameter is a selector expression, element or jQuery object. The filter parameter is a selector expression that narrows down the search for ancestors between the selector and the stops parameter.


Let us now see an example to implement the jQuery parentsUntil() method −

 Live Demo

<!DOCTYPE html>
div {
.demo * {
   display: block;
   border: 2px solid yellow;
   color: blue;
   padding: 10px;
   margin: 10px;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
      $("span").parentsUntil("div").css({"color": "blue", "border": "3px dashed blue"});
<body class="demo">great-great-grandparent


This will produce the following output−

Updated on 31-Dec-2019 07:40:08