티스토리 뷰

이론/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, 자바스크립트 제이쿼리 비교, 반복문 - 별도움이 안됐음.

.each()

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함