html - Javascript hideshow function -
hi i've been trying hideshow function , came across 1 works fine. problem me div hidden , displayed onclick rather displayed hidden. here sample code:
<!doctype html> <html> <head> <script> function hideshow(which){ if (!document.getelementbyid) return if (which.style.display=="none") which.style.display="block" else which.style.display="none" } </script> <style> #adiv { width: 320px; height: 320px; background: green; } </style> </head> <body> <a href= "javascript:hideshow(document.getelementbyid('adiv'));";>clickme!</a> <div id="adiv"> </div>
hope has enough info :)
you can hide div in 2 popular ways:
(1) hide using css
add display:none
div hide div whether js enabled or not. can use this:
<div id="adiv" style="display:none"> </div>
(2) hide using js
hiding via js useful if don't want div hidden users don't have js enabled. there various ways hide div using automatically executing js. below simple way this.
<body onload="hideshow(document.getelementbyid('adiv'));"> <a href= "javascript:hideshow(document.getelementbyid('adiv'));";>clickme!</a> <div id="adiv"> </div>
Comments
Post a Comment