• 技术文章 >web前端 >js教程

    jquery怎么去除class属性

    青灯夜游青灯夜游2021-11-25 10:35:35原创1034

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

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

    jquery去除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属性的详细内容,更多请关注php中文网其它相关文章!

    声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。
    专题推荐:jquery class属性
    上一篇:简单理解一下Node.js中的Buffer模块 下一篇:jquery怎么移除td元素中的指定属性
    千万级数据并发解决方案

    相关文章推荐

    • jquery怎样实现元素自动消失又显示• jquery怎样在最后增加一行信息• jquery怎样隐藏某列元素• jquery怎样改变元素对象的值• jquery怎样给元素增加属性值
    1/1

    PHP中文网