$('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
});
New class for element on click and reset classes for other elements [closed]
-
30-07-2022 - |
Question
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.
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow