Easy Tutorial
❮ Traversing First Misc Deferred Pipe ❯

jQuery each() Method

jQuery Traversing Methods

Example

Output the text of each <li> element:

$("button").click(function(){
    $("li").each(function(){
        alert($(this).text())
    });
});

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

Parameter Description
function (index,element) Required. A function to run for each matched element. index - The index position of the selector. <br> <br> element - The current element (also accessible via the "this" selector).

jQuery Traversing Methods

❮ Traversing First Misc Deferred Pipe ❯