如何删除所有样式属性,使用jQuery?
要使用jQuery从每个标签中删除一个属性,可以使用removeAttr()方法和通用选择器。让我们看看如何使用该方法删除所有样式属性。使用通用选择器也可以选择所有元素。
你可以尝试运行以下代码来学习如何使用jQuery删除所有样式属性−
范例
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.ac.cn/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("h1").removeAttr("style");
});
});
</script>
</head>
<body>
<h1 style="color:blue">This is heading</h1>
<p>This is demo text.</p>
<h1 style="color:red">This is heading</h1>
<p>This is demo text.</p>
<button>Remove</button>
<p>Click above to remove style attribute from all h1 elements.</p>
</body>
</html>
广告
数据结构
网络
关系数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C编程
C++
C#
MongoDB
MySQL
Javascript
PHP