如何使用jQuery删除所有样式属性?
要使用jQuery从每个标签中删除属性,请使用removeAttr()方法并使用通用选择器。让我们看看如何使用该方法删除所有样式属性。也可以使用通用选择器选择所有元素。
您可以尝试运行以下代码,以了解如何使用jQuery删除所有样式属性-
示例
<!DOCTYPE html>
<html>
<head>
<script src="https://cdn.staticfile.org/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>热门推荐
10 祝福语对联文案简短大气
11 兔年祝福语简短100字
12 韩语贺卡祝福语简短版
13 给孙子祝福语简短独特
14 生日祝福语舅舅 简短独特
15 新大学开学祝福语简短
16 14年祝福语简短情话
17 祝父母节日祝福语简短
18 结业蛋糕男生祝福语简短