First you need to bind the click event to the CSS class “btn” using the jQuery selector, this will allow you to manipulate all the buttons at the same time.
Then find the previously selected button, delete the selected class and add the regular class.
Finally, delete the regular class with the button pressed and add the selected class.
$('.btn').bind('click', function () { var previouslySelectedButton = $('.course-btn-tab-selected'); var selectedButton = $(this); if (previouslySelectedButton) previouslySelectedButton.removeClass('course-btn-tab-selected').addClass('course-btn-tab'); selectedButton.removeClass('course-btn-tab').addClass('course-btn-tab-selected'); });
Alternatively, here is a working example using your HTML: jsFiddle
source share