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

前端 未结 7 1519
星月不相逢
星月不相逢 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:38

    Per the spec, if you want to set the priority, not just the value, you have to use setProperty, like so:

    document.body.style.setProperty ("color", "green", "important");
    

提交回复
热议问题