Posted By

martinkas on 02/06/08


Tagged

css visibility html


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

jero


Show/Hide Element


 / Published in: JavaScript
 

Will toggle an element's style.visibility, or set it to visible/hidden as selected

  1. // show or hide a selected element
  2. // if no state is given, the visibility is toggled
  3. // otherwise visibility is set to hidden or visible as selected
  4. function showHide(e, state) {
  5. el = document.getElementById(e);
  6. if (state == "hidden") {
  7. el.style.visibility = "hidden";
  8. } else if (state == "visible") {
  9. el.style.visibility = "visible";
  10. } else {
  11. el.style.visibility = el.style.visibility == "visible" ? "hidden" : "visible";
  12. }
  13. }

Report this snippet  

You need to login to post a comment.