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
  • 37,241
  • 25
  • 195
  • 267
Jitender
  • 7,593
  • 30
  • 104
  • 210
  • 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
  • 24,020
  • 20
  • 85
  • 130
1

You can use .attr():

$('.pop').attr('class','pop');
h2ooooooo
  • 39,111
  • 8
  • 68
  • 102
Anton
  • 32,245
  • 5
  • 44
  • 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,570
  • 2
  • 27
  • 51
0

Just write it as:

$(".pop").removeClass("check");
Harry
  • 87,580
  • 25
  • 202
  • 214
John Kentucky
  • 876
  • 6
  • 10