jQueryその他each()メソッド

❮jQueryその他のメソッド

各<li>要素のテキストを警告します。

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

定義と使用法

each()メソッドは、一致した要素ごとに実行する関数を指定します。

ヒント: return falseを使用すると、ループを早期に停止できます。


構文

$(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その他のメソッド