I was trying to make a script that when you click an image, a div is made hidden or visible. I'm not really sure how to describe it other than that, so here's the code. <script language="JavaScript"> visibility = visible; function menu(whichMenu){ if (document.getElementById) {if (document.getElementById(whichMenu).style.visibility == visible){ whatState = hidden; } else {whatState = visible; } document.getElementById(whichMenu).style.visibility = whatState; } else { if (document[whichMenu].visibility == visible){ whatState = hidden; } else {whatState = visible; } document[whichMenu.visibility = whatState; } } </script> Code (markup): The image is just simply: <img onClick="menu('leftcontent1')" ... Code (markup): Can someone tell me why this isn't working? Thanks!
visible, hidden should be a string and not a variable. if you want you can set a variable in the global scope that says : var visible = "visible"; var hidden = "hidden"; Code (markup): good luck
You've seriously overcomplicated this! All you need is a function like: function toogle(id) { var elem = document.getElementById(id); if(!elem) return; if(elem.style.visibility == 'hidden') elem.style.visibility = 'visible'; else elem.style.visibility = 'hidden'; } <img onClick=toggle('leftcontent1') ...