我是靠谱客的博主 正直发夹,这篇文章主要介绍jquery怎么去除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属性内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(168)

评论列表共有 0 条评论

立即
投稿
返回
顶部