How to include !important in jquery

0 votes
asked Dec 31, 2009 by soft

I am trying to add !important in the css attribute using jQuery like

$("tabs").css('height','650px;!important');

but !important has no effect. How to include !important in jquery?

4 Answers

0 votes
answered Dec 31, 2009 by marc-w

You don't need !important when modifying CSS with jQuery since it modifies the style attribute on the elements in the DOM directly. !important is only needed in stylesheets to disallow a particular style rule from being overridden at a lower level. Modifying style directly is the lowest level you can go, so !important has no meaning.

0 votes
answered Dec 31, 2009 by klokop

Apparently it's possible to do this in jQuery:

$("#tabs").css("cssText", "height: 650px !important;");

Src: http://bugs.jquery.com/ticket/2066

0 votes
answered Dec 5, 2014 by burner

I solved this problem with:

inputObj.css('cssText', inputObj.attr('style')+'padding-left: ' + (width + 5) + 'px !IMPORTANT;');

So no inline-Style is lost, an the last overrides the first

0 votes
answered Sep 15, 2017 by user3711819

It is also possible to add more important properties:

inputObj.attr('style', 'color:black !important; background-color:#428bca !important;');

Welcome to Q&A, where you can ask questions and receive answers from other members of the community.
Website Online Counter

...