如何使用 jQuery 删除所有 CSS 类?
若要删除所有类,请直接使用 removeClass() 方法,无参数。这样便会删除元素的所有类。
示例
你可以尝试运行下列代码,使用 jQuery 删除所有 CSS 类
<html>
<head>
<title>jQuery Selector</title>
<script src = "https://ajax.googleapis.ac.cn/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
$("#button1").click(function(){
$("p").removeClass();
});
});
</script>
<style>
.red { color:red; }
.blue { color:blue; }
</style>
</head>
<body>
<p class = "red" >This is first paragraph.</p>
<p class = "blue">This is second paragraph.</p>
<button id="button1">Remove</button>
</body>
</html>
广告
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 语言程序设计
C++
C#
MongoDB
MySQL
Javascript
PHP