1

I want to remove class from div but selector class like: I want to remove only 'check' from below div.

Note: class name are dynamic. Its name can be anything.

<div class="pop check"></div>
$(function(){
$('.pop').not('pop').removeClass()  // not working
})

working code

$(function(){
$('.pop').removeClass().addClass('pop')
})

Is there any better way to do this

Cœur
  • 34,719
  • 24
  • 185
  • 251
Jitender
  • 7,057
  • 25
  • 92
  • 193
  • possible duplicate of [Using JQuery removeClass() to remove all classes but one](http://stackoverflow.com/questions/14322225/using-jquery-removeclass-to-remove-all-classes-but-one) as well as [Remove all classes except one](http://stackoverflow.com/questions/5363289/remove-all-classes-except-one) etc. – h2ooooooo Oct 18 '13 at 09:31
  • Answer here .. [jQuery documentation](http://api.jquery.com/removeClass/)`:p` – Stphane Oct 18 '13 at 09:36

4 Answers4

2

You can remove your class by:

$(function() {
    $('.pop').removeClass('check')
});
Manolo
  • 20,308
  • 18
  • 73
  • 124
1

You can use .attr():

$('.pop').attr('class','pop');
h2ooooooo
  • 37,963
  • 8
  • 65
  • 101
Anton
  • 31,487
  • 5
  • 43
  • 54
  • 1
    +1. This would be better if all classes except the selector class needs to be removed. – Harry Oct 18 '13 at 09:38
1

Try this:

if($(".pop").attr("class")!="pop"){
   $(".pop").attr("class","").addClass('pop');//to remove all classes and add pop class
}
Somnath Kharat
  • 3,550
  • 2
  • 26
  • 50
0

Just write it as:

$(".pop").removeClass("check");
Harry
  • 83,910
  • 24
  • 185
  • 203
John Kentucky
  • 828
  • 6
  • 8