0

I'm having trouble showing and hiding a tag on my page.

When the page loads I have

<a id="mylink" class="hiddenClass">...</a>

hiddenClass has display: none

When a certain event occurs, I use javascript to try and show the element in block style

document.getElementById("mylink").display = "block";

It doesn't show it. When I alert document.getElementById("mylink").display it says block.. but it's not showing.

How can I fix this..? And, in general, what is the best way to show and hide DOM elements?

2 Answers 2

6

You need to do:

document.getElementById("mylink").style.display = "block";
Sign up to request clarification or add additional context in comments.

Comments

0

You could remove that class

document.getElementById("mylink").className = '';

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.