tags:

views:

107

answers:

3

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

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

but There is no effect of !important. How to include !important in jquery?

+5  A: 

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.

Marc W
Unless you want to override an existing !important rule…
David Dorward
Yeah: if there’s an `!important` in the stylesheet that you’re trying to override, you’d need it in `$().css()`.
Paul D. Waite
+4  A: 

While i think you don't need !important in your code "at least in normal cases" because using your code that means that jquery will add inline css style which is more power than any other class and no need for !important in this case.

But i think to make it work as you want, just put !important then the semicolon.

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

Also note something in your code, what "tabs" is? is it a tag? "don't think so"

if its a class you need to write it like this:

$('.tabs')

and if its an id you need to write it like this:

$('#tabs')
Amr ElGarhy
+3  A: 

Apparently it's possible to do:

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

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

klokop
wow, this is the answer..... Thanks
adardesign
i liked this trick, first time to know, thanks @klokop
Amr ElGarhy