JavaScript automagically hide and show an HTML tag (DIV, P, whatever)


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



Copy this code and paste it in your HTML
  1. <a href="javascript:viewMore('two');" id="xtwo">... more</a>
  2. <p>I see one.</p>
  3. <p id="two" style="display:none">I see two.</p>
  4.  
  5.  
  6. function viewMore(div) {
  7. obj = document.getElementById(div);
  8. col = document.getElementById("x" + div);
  9.  
  10. if (obj.style.display == "none") {
  11. obj.style.display = "block";
  12. col.innerHTML = "... less";
  13. } else {
  14. obj.style.display = "none";
  15. col.innerHTML = "... more";
  16. }
  17. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.