I'm unable to inject a style with an “!important” rule

前端 未结 7 1494
星月不相逢
星月不相逢 2020-12-05 04:19

I tried to inject a style using this code:

document.body.style.color=\'green!important\';

Per the CSS cascade ref, by applying the !i

相关标签:
7条回答
  • 2020-12-05 04:51

    all answers are great but they all assumed the value of the attribute is fixed,, what if not

    take look at my solution

    this.style.setProperty("color", $(this).css('color'), "important");
    

    instead of hand writing the value, I got it using jquery $(this).css('attr')

    0 讨论(0)
提交回复
热议问题