How can I show an element that has display: none in a CSS rule?

后端 未结 4 841
栀梦
栀梦 2021-02-03 17:29

I have a really simple external css stylesheet that has the following :

div.hideBox {
    display:none;
}

So when the html page loads, the div

4条回答
  •  孤街浪徒
    2021-02-03 17:58

    Because setting the div's display style property to "" doesn't change anything in the CSS rule itself. That basically just creates an "empty," inline CSS rule, which has no effect beyond clearing the same property on that element.

    You need to set it to something that has a value:

    document.getElementById('mybox').style.display = "block";
    

    What you're doing would work if you were replacing an inline style on the div, like this:

    
    
    document.getElementById('mybox').style.display = "";
    

提交回复
热议问题