0

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?

1
  • 4
    document.getElementById("pop-up") . Note the ( & ), but you have used [ & ] Commented Jul 25, 2016 at 10:54

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

Comments

2

Try replacing the square brackets with parentheses;

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.