首页 > 解决方案 > jQuery删除多个样式

问题描述

我想使用 jQuery 将我的所有 css 设置为 null。我知道你可以做到

$("[class^=col-]").css('width', '');
$("[class^=col-]").css('right', '');
$("[class^=col-]").css('margin', '');
$("[class^=col-]").css('position', '');

但是否可以在一个命令中完成,例如:

$("[class^=col-]").css('');

编辑:我查看了上面的帖子并看到了答案。

通过删除样式属性,它可以完美地工作$("[class^=col-]").removeAttr("style")

标签: javascriptjqueryhtmlcss

解决方案


您需要使用这些属性的默认值来覆盖您设置的值

$(document).ready(function() {
  $("[class^=col-]").css({
    'width': 'auto',
    'position': 'inherit',
    'margin': '0',
    'right': '0'
  });
});
.col-md-12 {
  width: 10px;
  position: fixed;
  margin: 10px;
  right: 10px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="col-md-12">some test</div>


推荐阅读