Show/Hide Element


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

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


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.