且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用jQuery/JavaScript删除所有CSS类?

更新时间:2022-11-26 23:14:18

$("#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 = '';