성능향상을 위한 팁-10
$(document).ready(function () {
$('.bold').click(function () {
$(this).addClass('changeColor');
setTimeout(function () {
$(this).removeClass('changeColor');
}, 1000);
});
});
→ 하위로 갈 수록 모호해진다.
$(document).ready(function () {
$('.bold').click(function () {var $element = $(this); // 변수로 선언
$element.addClass('changeColor');
setTimeout(function () {
$element.removeClass('changeColor');
}, 1000);
});
});
댓글 1개
좌측코드에서 "this" 2개는 서로 다른 객체를 가르키지 않나요?