Jump to content

change visibility


Matej
 Share

Recommended Posts

<div id="ahoj"></div><div id="lol"></div><div id="cai"></div><button id="matek"> cau </button>   function sg(){x=document.getElementById("cai");g=x.style.display;if(g=="none"){g=="block"}else{g=="none"};} window.onload=zmena;function zmena(){    document.getElementById("matek").onclick=sg;}

i have set #cai{display:none;}

Can you tell me whats wrong with my script and why it isnt workign? (its writting only error nothing more)// on the different IDE it writtes"none is not defined

Edited by Matej
Link to comment
Share on other sites

1) Because it thinks none is a variable , wait you seemed have fixed it? by comparing to text 'none' or 'block' which is correct way.

 

2) you are not assigning 'block', 'none' to g but just comparing it again like it is use in if else condition.

 

3) g now equal 'none' or 'block' but you are are not applying this to the element in question.

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...