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

jQuery prevAll() method

jQuery prevAll() method

jQuery Traversal Methods jQuery Traversal Methods

Example

Return each with class name "start"

  • all sibling elements before the:

    $

    (

    document

    )

    .

    ready

    (

    function

    (

    )

    {

    $

    (

    "

    li.start

    "

    )

    .

    prevAll

    (

    )

    .

    css

    (

    {

    "

    color

    "

    :

    "

    red

    "

    ,

    "

    border

    "

    :

    "

    2px solid red

    "

    }

    )

    ;

    }

    )

    ;

    Result:

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

    Try it »


    Definition and Usage

    The prevAll() method returns all sibling elements before the selected element.

    Sibling elements are elements that share the same parent element.

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

    Related methods:

    • prev() - returns the previous sibling element of the selected element
    • prevUntil() - returns all sibling elements before each element between two given arguments

    Syntax

    $(

    selector

    ).prevAll(

    filter

    )

    Parameters Description
    filter Optional. Specifies a selector expression to narrow down the search for sibling elements before the element.
     **注意:**如需返回多个同级元素,请使用逗号分隔每个表达式。 |
    
    

    More examples

    Narrow down the search
    How to filter the search for sibling elements before the element.

    Return multiple sibling elements
    How to use the filter parameter to return those with class names "1", "2", and "3"

    all sibling elements of the element.

    Select

    all sibling elements before the
    How to select

    all sibling elements before the.

    Select

    all siblings before

    Element
    How to select each

    all siblings before the element

    .


    jQuery Traversal Methods jQuery Traversal Methods