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

jQuery each() method

jQuery each() method

jQuery Traversal Methods jQuery Traversal Methods

Example

Output each

  • element's text:

    $

    (

    "

    button

    "

    )

    .

    click

    (

    function

    (

    )

    {

    $

    (

    "

    li

    "

    )

    .

    each

    (

    function

    (

    )

    {

    alert

    (

    $

    (

    this

    )

    .

    text

    (

    )

    )

    }

    )

    ;

    }

    )

    ;

    Try it »


    Definition and Usage

    The each() method specifies a function to run for each matched element.

    **Tip:** Returning false can be used to stop the loop early.


    Syntax

    $(

    selector

    ).each(function

    (index,element)

    )

    Parameters Description
    function*(index,element)* Required. Specifies the function to run for each matched element.
    • index - The index position of the selector.
    • element - The current element (the "this" selector can also be used).
    • |

      jQuery Traversal Methods jQuery Traversal Methods