I have a HTML UL element that I want to hide with the .hidden property dynamically with JavaScript. Problem is, when there is a CSS rule: display: block on the element, the hidden property does not work.
document.getElementById('myid').hidden = true;
#myid {
display: block;
}
<div id="myid">Lorem ipsum</div>
The browser adds the hidden property to the element correctly, but the element does not hide because display: block is set.
I expected that JavaScript will override the CSS. What use is then to have the hidden property?
Why is this? and is this a bug?
2
Answers
You need a CSS rule
[hidden] {display:none!important;}
. Something like this.You can toggle CSS classes:
CSS classes:
HTML: