I've made a simple switch button. Classes are changing well but when I have multiple instances of this button it doesn't keep the original selection.
Thanks in advance
HTML
<ul class="button-switch"> <li><a href="#" class='active'>Spider-Man</a></li> <li><a href="#">Iron Man</a></li> <li><a href="#">Thor</a></li> <li><a href="#">Hulk</a></li> </ul> JQUERY
$('.button-switch li a').click(function(e) { e.preventDefault(); $('.button-switch li a').removeClass('active'); $(this).addClass('active'); }); JS fiddle example https://jsfiddle.net/t1gsp90j/1/