JS去除div中的style

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JS去除div中的style相关的知识,希望对你有一定的参考价值。

<!--通过style属性直接添加-->
<div style="width:100px" id="div"></div>
<!--通过class添加-->
<style type="text/css">
.abc{width:100px;}
</style><div class="abc" id="div2"></div>
<script type="text/javascript">
//直接去掉style
$("#div").removeAttr("style"); 
//去掉div的class
$("#div2").removeClass("abc");
</script>

方法说明:

removeAttr() 方法从被选元素中移除属性。

removeClass() 方法从被选元素移除一个或多个类。


本文出自 “8808968” 博客,谢绝转载!

以上是关于JS去除div中的style的主要内容,如果未能解决你的问题,请参考以下文章