如何使用 jQuery 刪除所有 CSS 類?
若要刪除所有類,請直接使用 removeClass() 方法,無引數。這樣便會刪除元素的所有類。
示例
你可以嘗試執行下列程式碼,使用 jQuery 刪除所有 CSS 類
<html>
<head>
<title>jQuery Selector</title>
<script src = "https://ajax.googleapis.com/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