Toggle Visibility


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

Heres how to use it:

link
sample content under div


Copy this code and paste it in your HTML
  1. <script>
  2. var status=1;
  3. function changeObjectVisibility(objectId, newVisibility) {
  4. // first get a reference to the cross-browser style object
  5. // and make sure the object exists
  6. var styleObject = getStyleObject(objectId);
  7. if(styleObject) {
  8. styleObject.visibility = newVisibility;
  9. return true;
  10. } else {
  11. // we couldn't find the object, so we can't change its visibility
  12. return false;
  13. }
  14. }
  15.  
  16. function getStyleObject(objectId) {
  17. // checkW3C DOM, then MSIE 4, then NN 4.
  18. //
  19. if(document.getElementById && document.getElementById(objectId)) {
  20. return document.getElementById(objectId).style;
  21. }
  22. else if (document.all && document.all(objectId)) {
  23. return document.all(objectId).style;
  24. }
  25. else if (document.layers && document.layers[objectId]) {
  26. return document.layers[objectId];
  27. } else {
  28. return false;
  29. }
  30. }
  31.  
  32. function toggle() {
  33.  
  34. if (status==1) {
  35. status=0;
  36. changeObjectVisibility('container','visible');
  37. } else {
  38. status = 1;
  39. changeObjectVisibility('container','hidden');
  40. }
  41. }
  42. </script>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.