Published in: JavaScript
<style type="text/css"> .divHide{display:none;} .divShow{display:block;} </style> <script type="text/javascript" language="javascript"> function showhide(obj) { var el=document.getElementById(obj); if (el.className == "divHide") { el.className = "divShow"; } else { el.className = "divHide"; } } </script> ... <a onclick="showhide('calendar');" href="#calendar">click here</a>.</p><a name="calendar"></a> <div id="calendar" class="divHide"></div>
Comments
Subscribe to comments
You need to login to post a comment.

The problem with this solution is that your element only should be displayed block but in the case you have an inline element or a table cell it will fail, so this solution is a little bit more flexible:
function showhide(obj) { var el=document.getElementById(obj); el.style.display=="none" ? el.style.display="" : el.style.display="none" }
Thanks for the comment. That is a better generalized way. I guess i made it to specific for my purpose.