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

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

    I would like to pose that it may not be working not so much due to any error in code (excepting the space) but more because modifying the body tag isn't a specific enough element, class, or what have you to create the desired effect.

    Like for instance the page text of a search result has a class of "st". all search results are each encapsulated in an

  • tag.

    So some code to such effect might look like this:

    var arr = document.getElementsByClassName('st');
    for(i=0; i

提交回复
热议问题