user4246994
user4246994

Reputation:

how to remove class of a div without knowning id of div?

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

Answers (4)

Milind Anantwar
Milind Anantwar

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

Majid Sadr
Majid Sadr

Reputation: 1071

$(".your_class").removeClass("your_class");

Upvotes: 0

Sajad Karuthedath
Sajad Karuthedath

Reputation: 15767

if you just need to remove the class for any div containing that particular class

$("div").removeClass('someClass'); 

Upvotes: 2

4dgaurav
4dgaurav

Reputation: 11506

$(".className").removeClass("className")

Upvotes: 5

Related Questions