Show image when clicking on text?
Go to solution
Solved by Ciccioo,
first, you set your div default to "display: none" in CSS, so that it won't show when the page loads
#targetDiv{ display: none;}
then, your code is good but you need to check things the other way around
if(theElementStyle.style.display == "block"){ theElementStyle.style.display = "none";}else{ theElementStyle.style.display = "block";}
because at the first run, the CSS property is "display: none", but the Javascript CSS attribute won't have any value (they're not set automatically by the CSS engine)
so you want the "else" block to be the one that has to be executed at the first run as well
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now