Reputation: 5
I'm attempting to change the CSS of a display:none to a display:block using the following command:
document.getElementById["pop-up"].style.display="block";
The problem is, despite defining the pop-up id in the css (see below), and following other instructions similar to this problem, I've not been able to get it to change.
#pop-up {
display: none;
}
What am I doing wrong?
Upvotes: 0
Views: 56
Reputation: 3093
Try replacing the square brackets with parentheses;
document.getElementById("pop-up").style.display="block";
Upvotes: 2
Reputation: 943537
getElementById
is a function (not an object where every element with an ID exists as a property).
You need to call it with ()
and not access properties with []
Make sure you open the Developer Tools in your browser and read the console. It would have told you that document.getElementById["pop-up"]
was undefined.
Upvotes: 3