如何使用jQuery删除所有CSS类? [英] How to remove all CSS classes using jQuery?
本文介绍了如何使用jQuery删除所有CSS类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
而不是单个调用$ code $(#item)。removeClass()对于每个单个类可能有一个类,是否有一个可以调用哪个函数从给定的元素中删除所有CSS类?
Instead of individually calling $("#item").removeClass()
for every single class an element might have, is there a single function which can be called which removes all CSS classes from the given element?
jQuery和原始JavaScript都可以正常工作。
Both jQuery and raw JavaScript will work.
推荐答案
$("#item").removeClass();
调用 removeClass
没有参数将删除所有
Calling removeClass
with no parameters will remove all of the item's classes.
您也可以使用(但不一定建议,正确方式是上面的一种):
You can also use (but is not necessarily recommended, the correct way is the one above):
$("#item").removeAttr('class');
$("#item").attr('class', '');
$('#item')[0].className = '';
如果你没有jQuery,那么这将是你唯一的选择:
If you didn't have jQuery, then this would be pretty much your only option:
document.getElementById('item').className = '';
这篇关于如何使用jQuery删除所有CSS类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文