이론/jQuery
[jQuery] 반복문 .each()
millfeel1298
2021. 10. 23. 19:33
$('선택자').each(함수);
원리는 for문과 비슷하다.
// jQuery
$('.el_boxUnit > div').each(function (idx) {
$(this).css({width: '100px', height: '100px'});
})
});
// idx는 JS for문의 i와 같다.
// JS
const $el_boxUnit_children = document.querySelector('.el_boxUnit').children;
for (let i = 0; i < $el_boxUnit_children.length; i++) {
$el_boxUnit_children[i].style.width = '100px';
$el_boxUnit_children[i].style.height = '100px';
}
See the Pen [jQuery] 반복문 .each() by mill (@millfeel) on CodePen.
[공부좌표]
jQuery 06 [ each 메서드 ] jQuery hover animation, 자바스크립트 제이쿼리 비교, 반복문 - 별도움이 안됐음.