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 탐색 방법