Cirrostratus
Cirrostratus

Reputation: 5

Attempting to change CSS using document.getElementById not working?

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

Answers (2)

atoms
atoms

Reputation: 3093

Try replacing the square brackets with parentheses;

document.getElementById("pop-up").style.display="block";

Upvotes: 2

Quentin
Quentin

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

Related Questions