Método jQuery each()

❮ Métodos transversales de jQuery

Ejemplo

Alerta el texto de cada elemento <li>:

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

Definición y uso

El método each() especifica una función para ejecutar para cada elemento coincidente.

Sugerencia: se puede usar return false para detener el bucle antes de tiempo.


Sintaxis

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

❮ Métodos transversales de jQuery