jQuery CSS !important

You cannot add an !important declaration to your CSS using jQuery’s .css method, but you can add it using .attr with style like so. This method keeps the original style declarations.

function setMyCSS( element, setting, value ) {
    $( element ).attr( 'style', function( i, s ) { return ( s || '' ) + setting + ':' + value + '!important;' } );
}

setMyCSS( 'body', 'background-color', 'red' );