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

jQuery next() method

jQuery next() method

jQuery Traversal Methods jQuery Traversal Methods

Example

Return each with class name "start"

  • the next sibling element of the:

    $(document).ready(function(){

    $("li.start").next().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 next() method returns the next sibling element of the selected element.

    Sibling elements are elements that share the same parent element.

    **Note:** This method returns only one element.

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

    Related methods:

    • nextAll() - returns all sibling elements after the selected element
    • nextUntil() - returns all sibling elements after each element between two given arguments

    Syntax

    $(

    selector

    ).next(

    filter

    )

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

    More examples

    Select every

    the next sibling element of the
    How to select each
    the next sibling element of the.

    Narrow down the search
    How to select each

    the next sibling of the

    .


    jQuery Traversal Methods jQuery Traversal Methods