English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The each() method traverses the jQuery object and executes a function for each selected element.
The each() method aims to make the DOM loop structure concise and clear, and less prone to errors.
$$(selector).each(function(index, element))
Iterate through each list item and pop up the text of each element:
$("button").click(function(){ $("li").each(function(){ alert($(this).text()); }); });Test and see‹/›
Used for return false and terminate each() loop:
$("button").click(function(){ $("div").each(function(index, element){ $("element").css("backgroundColor", "yellow"); if($(this).is("#stop")){ $("span").text("div stop index #" + index); return false; } }); });Test and see‹/›
Parameter | Description |
---|---|
function(index, element) | Specify the function to be executed for each selected element
|