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>
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
评论(0)