Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

jQuery prevUntil() method

jQuery prevUntil() method

jQuery Traversal Methods jQuery Traversal Methods

Example

Return the two with class names "start" and "stop"

  • all sibling elements between the:

    $(document).ready(function(){

    $("li.start").nextUntil("li.stop").css({"color":"red","border":"2px solid red"});

    });

    Result:

    • li (sibling with class name "stop")
    • li (sibling)
    • li (sibling)
    • li (sibling)
    • li (sibling with class name "start")
    • li (sibling)
    • li (sibling)

    Try it »


    Definition and Usage

    The prevUntil() method returns selector The difference between stop all sibling elements before each element between the two.

    Sibling elements are elements that share the same parent element.

    **DOM Tree:** This method traverses backward along the sibling elements of the DOM element.

    **Note:** If both parameters are empty, this method returns all sibling elements before the element (same as prevAll() method).

    Related methods:

    • prev() - returns the previous sibling element of the selected element
    • prevAll() - returns all sibling elements before the selected element

    Syntax

    $(

    selector

    ).prevUntil(

    stop,filter

    )

    Parameters Description
    stop Optional. A selector expression, element, or jQuery object indicating where to stop searching for matching sibling elements before the element.
    filter Optional. Specifies a selector expression to narrow down the search for sibling elements between selector The difference between stop the two.
     **注意:**如需返回多个同级元素,请使用逗号分隔每个表达式。 |
    
    

    More examples

    Narrow down the search
    Use two parameters to filter the search for sibling elements before each element between the two parameters.

    Return multiple sibling elements
    How to return multiple sibling elements between two parameters.

    DOM
    Use a DOM element instead of a selector to return all sibling elements between two given parameters.

    Using a DOM with two parameters
    Use a DOM with two parameters instead of a selector to filter the search for sibling elements before each element between the two parameters.


    jQuery Traversal Methods jQuery Traversal Methods