Toggle (Show/Hide) Element


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <script type="text/javascript">
  2. <!--
  3. function toggle_visibility(id) {
  4. var e = document.getElementById(id);
  5. if(e.style.display == 'block')
  6. e.style.display = 'none';
  7. else
  8. e.style.display = 'block';
  9. }
  10. //-->
  11. </script>
  12.  
  13. Inline usage:
  14. <a href="#" onclick="toggle_visibility('foo');">Click here to toggle visibility of element #foo</a>
  15. <div id="foo">This is foo</div>

URL: http://css-tricks.com/snippets/javascript/showhide-element/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.