Asked • 04/01/19

How to apply !important using .css()?

I am having trouble applying a style that is `!important`. I’ve tried: $("#elem").css("width", "100px !important");This does **nothing**; no width style whatsoever is applied. Is there a jQuery-ish way of applying such a style without having to overwrite `cssText` (which would mean I’d need to parse it first, etc.)?**Edit**: I should add that I have a stylesheet with an `!important` style that I am trying to override with an `!important` style inline, so using `.width()` and the like does not work since it gets overridden by my external `!important` style.Also, the value that will override the previous value **is computed**, so I cannot simply create another external style.

Steven S.

Instead of overriding the style, could you use jQuery to remove the styles you don't want and add the new ones? Not sure if this will work without seeing what is going on exactly.
Report

04/02/19

1 Expert Answer

By:

Gabriel F. answered • 11/25/19

Tutor
5.0 (85)

Full Stack Software Developer and Mentor

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.