3

I want to set all my css to null with the use of jQuery. I know you can do it like

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

but is it possible to do it in one command, like:

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

Edit: i have looked in the post above and saw the answer.

By removing the style atrribute it works perfectly $("[class^=col-]").removeAttr("style")

Salman A
  • 262,204
  • 82
  • 430
  • 521
Tim567
  • 775
  • 1
  • 5
  • 22

1 Answers1

1

You need to use the default values for those properties to override the values you have set

$(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>
Ankit Agarwal
  • 30,378
  • 5
  • 37
  • 62