JAVA/열일하는 블로그
[Javascript] jQuery의 $(data).each() 함수 (반복문)
샛별KIM
2021. 12. 10. 09:53
참고 블로그)
jQuery의 each() 메서드 알아보기
jQuery - each() 메서드 jQuery를 사용해 배열을 관리하고자 할 때 each() 메서드를 사용할 수 있습니다. each() 메서드는 매개 변수로 받은 것을 사용해 for in 반복문과 같이 배열이나 객체의 요소를 검사
webclub.tistory.com
$(data).each(function(index, item){ });
jQuery의 반복문이다.
index는 배열의 인덱스이며, item은 해당 인덱스가 가진 값을 의미한다.
$('.list li').each(function (index, item) {
// 인덱스는 말 그대로 인덱스
// item 은 해당 선택자인 객체를 나타냅니다.
$(item).addClass('li_0' + index);
// item 과 this는 같아서 일반적으로 this를 많이 사용합니다.
// $(this).addClass('li_0' + index);
});
//출처: https://webclub.tistory.com/455 [Web Club]