jQuery Style How to - Overwrite !important








Question

We would like to know how to overwrite !important.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-1.8.3.js'></script>
<style type='text/css'>
body {<!--from w  w w . j a v  a  2  s.c  o m-->
  padding: 2em;
}

.foo {
  border: 3px solid black !important;
}
</style>
<script type='text/javascript'>
$(function(){
    $( '.foo' ).each(function () {
        this.style.setProperty( 'border', 'none', 'important' );
    });
});
</script>
</head>
<body>
  <div class="foo">Foo</div>
</body>
</html>

The code above is rendered as follows: