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 ?
!importantif you're setting styles on the element itself, unless there's something else that's!importantelsewhere. If the one elsewhere is!important, presumably whoever added it decided it shouldn't be overridden. Generally, the use of!importantis seen as a bad solution to a CSS issue that will come back to bite you, as it sounds it may have done here.document.getElementById("loginActive").style.display = "block", "important";– that makes no sense, resp. it doesn’t do what you think it does. (Go look up the JS comma operator, if you want to know what your line actually means.) And I don’t understand the question – in the line above, you are able to set a style property with important for the body – so what is stopping you from using that exact same syntax in the second line as well …?