I’m using this snippet to add a class based on its id:
$('.block').click(function() {
$('#bg').addClass($(this).attr('id'));
});
but need to remove the last added class if one has been added as its causing problems when clicking previously clicked buttons as the current (higher) class overides lower, how can this be achieved?
Just use removeClass to clear the div first.
jsFiddle example