jquery怎么去除class属性

发布时间:2022-05-16 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了jquery怎么去除class属性脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

方法:1、用attr()class属性的值设为空,语法“$(selector).attr("class","")”;2、用removeAttr()移除class属性,语法“$(selector).removeAttr("class")”。

本教程操作环境:windows7系统、jquery1.10.2版本、Dell G3脑。

jquery去除class属性有两种方法:

  • 使用attr()将元素中class属性的值设为空

    语法:$(selector).attr("class","")

  • 使用removeAttr()移除元素中的class属性

    语法:$(selector).removeAttr("class")

示例:

<!DOCTYPE htML>
<html>
	<head>
		<;meta charset="utf-8">

		<script src="js/jquery-1.10.2.min.js"></script>
		<script>
			$(document).ready(function() {
				$("button").click(function() {
					$(".box1").attr("class", "");
					$(".box2").removeAttr("class");
				});
			});
		</script>
		<style>
			div {
				border: 1px solid red;
				margin: 10px;
			}

			.box1 {
				background-color: #Ffc0CB;
			}

			.box2 {
				background-color: green;
				color: whITe;
			}
		</style>
	</head>
	<body>

		<div class="box1">测试文本</div>
		<div class="box2">测试文本</div>
		<br>
		<button>去掉class属性</button>

	</body>
</html>

1.gif

相关视频教程推荐:jQuery视频教程

以上就是jquery怎么去除class属性的详细内容,更多请关注脚本宝典其它相关文章

脚本宝典总结

以上是脚本宝典为你收集整理的jquery怎么去除class属性全部内容,希望文章能够帮你解决jquery怎么去除class属性所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: