Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Overriding !important with css or jquery

People also ask

Can you override important in CSS?

Overriding the ! important modifier. add a CSS rule with the same selector at a later point than the existing one (in a tie, the last one defined wins).

Can jQuery override CSS?

cssHooks. Hook directly into jQuery to override how particular CSS properties are retrieved or set, normalize CSS property naming, or create custom properties.

Which is better CSS or jQuery?

What's the difference? In a nutshell, CSS uses your graphic card to process the transition, where as using jQuery uses your main processor. However jQuery is generally more backwards compatible than CSS. That said, CSS transitions will revert to jQuery if the browser doesn't support CSS transitions.

How Important Is CSS in jQuery?

You can do this: $("#elem"). css("cssText", "width: 100px ! important;");


Here you go:

$( '.someclass' ).each(function () {
    this.style.setProperty( 'border', 'none', 'important' );
});

Live demo: http://jsfiddle.net/Gtr54/

The .setProperty method of an element's style object enables you to pass a third argument which represents the priority. So, you're overriding an !important value with your own !important value. As far as I know, it is not possible to set the !important priority with jQuery, so your only option is the built-in .setProperty method.


You can also do this:

$(".someclass").css("cssText", "border: none !important;");

This should help.

$(".someclass").attr("style","border:none!important");

Updated, so as not to overwrite all styles:

var existingStyles = $(".someclass").attr("style");
$(".someclass").attr("style", existingStyles+"border:none!important");