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.
最安全的解决方法是添加一个类,然后在CSS中做魔术:-),
addClass()
并removeClass()
应完成工作。