Reputation: 129
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
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