使用JavaScript从元素中删除CSS类(无jQuery) [英] Remove CSS class from element with JavaScript (no jQuery)

查看:181
本文介绍了使用JavaScript从元素中删除CSS类(无jQuery)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以让我知道如何使用JavaScript只删除一个元素上的类?
请不要给我一个答案与jQuery,因为我不能使用它,我不知道任何关于它。

Could anyone let me know how to remove a class on an element using JavaScript only? Please do not give me an answer with jQuery as I can't use it, and I don't know anything about it.

推荐答案

您可以简单地将元素类设置为无。

You could simply set the elements class to nothing.

document.getElementById("whatever").className = "";

或如果您想保留特定课程,可以重置课程

or if you wanted to keep a particular class you could just reset the class

document.getElementById("whatever").className = "";
document.getElementById("whatever").className = "classToKeep";

这篇关于使用JavaScript从元素中删除CSS类(无jQuery)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆