jQuery each() Metoda

❮ Metody przechodzenia jQuery

Przykład

Ostrzegaj o tekście każdego elementu <li>:

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

Definicja i użycie

Metoda each() określa funkcję do uruchomienia dla każdego dopasowanego elementu.

Wskazówka: return false może służyć do wcześniejszego zatrzymania pętli.


Składnia

$(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)

❮ Metody przechodzenia jQuery