Reputation:
$('.toggle').addClass('change_button').removeClass('toggle');
$(this).removeClass('change_button').addClass('toggle');
i have provided the demo of complete code below in the first comment.
i have 2 sets of buttons
1st set
1.Lite
2.Medium
3.Heavy
Demo: Fiddle
2nd set
1.Yes
2.No
what i want is those sets must act as radio buttons like demo provided below in the first comment
instead of radio buttons i have here block buttons and when the button is selected i want to change bagraund color
Upvotes: 0
Views: 203
Reputation: 123739
Try this:-
$('.change_button.toggle',$(this).closest('div')).removeClass('toggle');
$(this).addClass('toggle');
});
Explanation:-
$('.change_button.toggle',$(this).closest('div')).removeClass('toggle');
This statement selects the elements with .change_button and .toggle class which resides in the parent div of the clicked element and removes its toggle
class.
$(this).addClass('toggle');
Adds the class the selected element.
Upvotes: 2