Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery remove multiple styles [duplicate]

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")

like image 783
Tim567 Avatar asked Aug 14 '26 01:08

Tim567


1 Answers

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>
like image 73
Ankit Agarwal Avatar answered Aug 16 '26 14:08

Ankit Agarwal