admin管理员组文章数量:1332339
Is it possible to remove all classes of an element that are not equal to a certain string,
for example, if I have the following HTML
<a href="" class="status pending"></a>
<a href="" class="status successful"></a>
<a href="" class="status unsuccessful"></a>
Could I remove all the classes that are not equal to status?
Is it possible to remove all classes of an element that are not equal to a certain string,
for example, if I have the following HTML
<a href="" class="status pending"></a>
<a href="" class="status successful"></a>
<a href="" class="status unsuccessful"></a>
Could I remove all the classes that are not equal to status?
Share Improve this question edited Jan 26, 2011 at 22:37 Šime Vidas 186k65 gold badges288 silver badges391 bronze badges asked Jan 26, 2011 at 22:26 sea_1987sea_1987 2,95412 gold badges46 silver badges69 bronze badges4 Answers
Reset to default 5You could do this:
removeClass().addClass('status')
Another option:
removeClass(function(i, c) { return c.replace('status', ''); });
or a bit faster
$('.status').attr('class','status');
will overwrite the class attribute of every element to hold only the 'status' value
if ($('a').hasClass("status")) {
$('a').removeClass().addClass("status")
} else {
$('a').removeClass()
}
If you just want the status class to remain on all links you could do:
$("a").attr("class", "status");
本文标签: javascriptjquery removeClass()Stack Overflow
版权声明:本文标题:javascript - jquery removeClass() - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742328737a2454255.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论