user472285 user472285 - 1 year ago 92
CSS Question

How to overwrite an !important CSS property in jQuery

I have css on my page's

and I would like to overwrite
overflow: visible !important;
. I have tried the jQuery script below, but that doesn't do it"

jQuery("body, #s4-workspace").css("overflow", "hidden !important");


body, #s4-workspace {
overflow: visible !important;

body {
height: 100%;
overflow: hidden; //overriden
width: 100%;

I know there are two overflow already, but sadly I don't have the hand on that, otherwise it would be too easy, wouldn't it?

Answer Source

As mentioned, ! important is not handled well by jQuery's css().

Here is a hack that will work if you don't mind overwriting the inline style attribute value (if it exists):

 jQuery("body, #s4-workspace")
     .attr("style", "overflow:hidden !important");

Like I said, it's a hack - but give it a try.


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download