jquery remove class
i got a class,
div.domtab div{
clear:both;
width:auto;
background:#eee;
color:#000;
padding:1em 1.5em;
}
and i cannot change it, and i not able to remove it i tried
$('#tag1').removeClass();
$('#tag1').removeClass('.domtab');
$('#tag1').removeCl开发者_如何学编程ass('div.domtab');
$('#tag1').removeClass('div.domtab div');
but it still not working.
clear:both
cause all my div not float left.....
Considering your markup is like:
<div class="domtab">
...
<div id="tag1"></div>
...
</div>
You can remove the class by
$('#tag1').closest('.domtab').removeClass('domtab');
try $('#tag1').removeClass('domtab');
You just missed out the line that is actually correct.
$('#tag1').removeClass('domtab');
The code above should do the trick.
The reason the above answers are correct, is because this method specifies "Class" in it's name, implying that it is ASSUMED you are giving it a valid class name. Being as "." implies a class, this becomes a redundancy.
Thus, when using "removeClass" a "." should not be used.
精彩评论