Skip to content
Related Articles
Open in App
Not now

Related Articles

jQuery | parentsUntil() with Example

Improve Article
Save Article
  • Last Updated : 13 Feb, 2019
Improve Article
Save Article

The parentsUntil() is an inbuilt method in jQuery that is used to find all the ancestor elements between two given elements in a DOM tree. The Document Object Model(DOM) is a World Wide Web Consortium standard. This defines for accessing elements in the DOM tree.


Parameters: It accepts a parameter “selector2” which is the last marked parent of the selected element in the tree.
Return Value: It returns all ancestors elements between two given elements.
jQuery code to show the working of parentsUntil() method:

        .anc * {
            display: block;
            border: 2px solid lightgrey;
            color: black;
            padding: 5px;
            margin: 15px;
        $(document).ready(function() {
                "color": "black",
                "border": "2px solid green"
<body class="anc">
    This is great-great-grandparent !
    <div style="width:400px;">
        This is great-grandfather element !
            This is grandparent !
            <li>This is direct parent element !
                <span>This is child element</span>

In the above code, all the ancestor elements between “span” and “div” get highlighted with green color.

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!