alucardu
alucardu

Reputation: 129

Set a css attribute to important through javascript

On my page I want to set the attribute display to block!important when there's a specific string in the url,

I've been doing some research, but can't find the correct answer. Using the code below I can set the background-color: green!important on the body, but I don't know how to target something else (the "loginActive" id element).

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

Any tips on how I can set display: block!important on the element #loginActive ?

Upvotes: 2

Views: 5426

Answers (1)

HoangND
HoangND

Reputation: 408

Try this

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

Or

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

But you shouldn't do that

Upvotes: 4

Related Questions