Domanda

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.

È stato utile?

Soluzione

$('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

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top