반복문 작성
조회수 498회
$(".list a:nth-child(1)").mouseover(function(){
$(".cursor li").hide();
$(".cursor li:nth-child(1)").show();
});
저 nth-child(1)부분의 숫자가 1씩 늘어나면서 계속 반복되려면 어떻게 작성할 수 있나요?
-
(•́ ✖ •̀)
알 수 없는 사용자
1 답변
-
1씩 늘리지 마시고 그냥 순회를 돌리세요. demo
$(".list a").each(function (i) { // index 획득 가능 $(this).mouseover(function () { $(".cursor li").eq(i).show(); // 획득한 index 사용 }).mouseout(function () { $(".cursor li").hide(); }); });
jQuery의
each()
메소드,eq()
메소드에 대해 알아보세요.
댓글 입력