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

jQuery siblings() method

jQuery siblings() method

jQuery Traversal Methods jQuery Traversal Methods

Example

Return each with class name "start"

  • all sibling elements of the:

    $

    (

    document

    )

    .

    ready

    (

    function

    (

    )

    {

    $

    (

    "

    li.start

    "

    )

    .

    siblings

    (

    )

    .

    css

    (

    {

    "

    color

    "

    :

    "

    red

    "

    ,

    "

    border

    "

    :

    "

    2px solid red

    "

    }

    )

    ;

    }

    )

    ;

    Result:

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

    Try it »


    Definition and Usage

    The siblings() method returns all sibling elements of the selected element.

    Sibling elements are elements that share the same parent element.

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

    **Tip:** Please use prev() or next() method to narrow down the search to only the previous sibling element or the next sibling element.


    Syntax

    $(

    selector

    ).siblings(

    filter

    )

    Parameters Description
    filter Optional. Specifies a selector expression to narrow down the search for sibling elements.

    More examples

    Narrow down the search
    How to use two parameters to filter the search for sibling elements.

    Select every

    all siblings of the element

    Element
    How to narrow down the search for each

    all siblings of the element

    element.


    jQuery Traversal Methods jQuery Traversal Methods