通过javascript将css属性设置为重要

时间:2016-01-26 10:40:22

标签: javascript css

在我的网页上,我想在网址中有特定字符串时将属性显示设置为block!important

我一直在做一些研究,但找不到正确的答案。使用下面的代码,我可以在正文上设置background-color: green!important,但我不知道如何定位其他内容("loginActive" id元素)。

:javascript
  if(window.location.href.indexOf("sign_up") > -1) {
    document.body.style.setProperty ("background-color", "green", "important");
    document.getElementById("loginActive").style.display = "block", "important";
  }

有关如何在元素display: block!important上设置#loginActive的任何提示?

1 个答案:

答案 0 :(得分:1)

试试这个

var item = document.getElementById("loginActive");
item.style. display = 'block !important';

或者

item.setAttribute('style', 'display:block !important');

但你不应该这样做

相关问题