Latest web development tutorials

jQuery each () method

jQuery traversal methods jQuery traversal methods

Examples

Output text of each <li> element:

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

try it"

Definition and Usage

each () method as a function of each matching element specified to run.

NOTE: Returns false can be used as soon as possible to stop the cycle.


grammar

$(selector).each(function(index,element))

参数 描述
function(index,element) 必需。为每个匹配元素规定运行的函数。
  • index- 选择器的 index 位置。
  • element- 当前的元素(也可使用 "this" 选择器)。


jQuery traversal methods jQuery traversal methods