I am in need of a simple solution to remove the selected class when clicking on an already highlighted button. I want only one button to be highlighted at a time.
http://jsfiddle.net/7wy7sjm5/1/
The reason why I first remove the class for all buttons is because I only want the clicked button to be highlighted, not the previously clicked ones. Additionally, if a button that is already highlighted is clicked again, I want to remove the highlight. I hope this explanation is clear.
$(".details-btn").on("click", function(){
var $this = $(this);
//Add/Remove selected for button
$(".details-btn").removeClass("selected");
$this.toggleClass("selected");});
I have tried different approaches, such as using .each() to cycle through each instance of the button and remove the class if it has it, but none of them are working as I would like.