Please note, this is a STATIC archive of website www.w3schools.com from 05 May 2020, cach3.com does not collect or store any user information, there is no "phishing" involved.
THE WORLD'S LARGEST WEB DEVELOPER SITE

jQuery Misc each() Method

❮ jQuery Misc Methods

Example

Alert the text of each <li> element:

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

Definition and Usage

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

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


Syntax

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

Parameter Description
function(index,element) Required. A 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 Misc Methods