Hey there! I have a question about resetting classes when a button is pressed. Here is the HTML setup I am working with:
<a class="test testclass">Test 1</a>
<a class="test testclass">Test 2</a>
<a class="test testclass">Test 3</a>
<a class="reset_all_classes">RESET ME</a>
And here is the jQuery code I am using:
$('.test').click(function(){
$(this).toggleClass('testclass testclass-active');
})
// Reset by removing all the testclass-active on all the <a>
$('.reset_all_classes').click(function(){
$('.test').toggleClass('testclass-active testclass');
})
When clicking a hyperlink with the test
class, the testclass
will change to testclass-active
. However, if both Test 1 and Test 3 are selected with testclass-active
, pressing the reset button will revert them back to testclass
, while leaving Test 2 with testclass-active
.
I'm looking for a way to keep Test 1 and Test 3 with the testclass-active
when resetting, while still reverting Test 2 back to testclass
. Any suggestions on how to achieve this?