html - Javascript: Toggle visibilty of a div -
I am trying to make a div visible / invisible using javascript. I have a function that should change the visibility to 'None', if it appears in the div and the 'view' if the div is none though it does not seem to work, please help is the code.
& lt; Script & gt; Function toggleTools () {var element = document.getElementById ('divTools'); If (element.style.visibility == 'visible') {element.style.visibility = 'hidden'; } And {element.style.visibility = 'visible'; }} & lt; / Script & gt;
I tried your code and worked for it please find the code below Set the visibility for the element otherwise it is not working in the beginning.
& lt; Script & gt; Function toggleTools () {var element = document.getElementById ('divTools'); If (element.style.visibility == 'visible') {element.style.visibility = 'hidden'; } And {element.style.visibility = 'visible'; }} & lt; / Script & gt; & Lt; Div id = "divTools" style = "visibility: visible" & gt; & Lt; P & gt; Some text & lt; / P & gt; & Lt; / Div & gt; & Lt; Input type = "button" onclick = "toggleTools ()" value = "click" />
Comments
Post a Comment