문제

All my <p>s have a class "A". I want to change the class of a <p> when it's clicked to class "B" and reset all others to class "A". Easy to change the <p>s to class "B", but completely stuck with reverting the others.

도움이 되었습니까?

해결책

$('p').click(function() {
    $('p').removeClass('B').addClass('A'); // revert all 'p's to 'A'
    $(this).removeClass('A').addClass('B'); // 'this' refers to the clicked object
});

DEMO

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top