jQuery gudan - each() method

example

output the text of each li element:

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

try it yourself

definition and usage

each() method specifies the function to run for each matching element.

tip:return false can be used to stop the loop early.

syntax

$().each(function(index,element))
parameter description
function(index,element)

required. Specify the function to run for each matching element.

  • index - selector index position
  • element - current element (can also use "this" selector)