admin管理员组文章数量:1392066
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.
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.
- you should be sharing relevant code, what needs to be done and what you have tried. – Milind Anantwar Commented Dec 18, 2014 at 6:48
- jquery uses events, so the question is when you need to delete them? – bto.rdz Commented Dec 18, 2014 at 6:49
- @AshokSri, do use some preffix/suffix for id e.g. foo1, foo2 etc? – user2575725 Commented Dec 18, 2014 at 6:52
-
You can specify a separate attribute, say
indicator="Y"
for the generateddiv
s and then while removing the classes, you can do:$("div[indicator='Y']").removeClass("your_class")
– ArinCool Commented Dec 18, 2014 at 6:52 - hi all, i've edited my question please understand the situation now – user4246994 Commented Dec 18, 2014 at 7:00
4 Answers
Reset to default 5$(".className").removeClass("className")
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');
});
if you just need to remove the class for any div containing that particular class
$("div").removeClass('someClass');
$(".your_class").removeClass("your_class");
本文标签: javascripthow to remove class of a div without knowning id of divStack Overflow
版权声明:本文标题:javascript - how to remove class of a div without knowning id of div? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744781627a2624749.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论