Reputation:
Hi i have a dynamic generated div's list with unique id's for every generated div's,
when click on one of the dynamic generated div this will change the selected div background color by this code $(this).addClass('add_color');
if again i click on another one div then the older selected div background color should change to default so i tried this code $(".add_color").removeClass(".add_color");
but it's not working, please help.
Upvotes: 2
Views: 2004
Reputation: 82231
You need to modify the click handler to add/remove class on click of divs:
$('body').on('click','.somedivs',function(){
$(".add_color").not($(this)).removeClass("add_color");
$(this).addClass('add_color');
});
Upvotes: 2
Reputation: 15767
if you just need to remove the class for any div containing that particular class
$("div").removeClass('someClass');
Upvotes: 2