Posted By

alexwilliams on 01/01/07


Tagged

javascript html formatting


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

Bluewall
NagaTragic1322


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


 / Published in: JavaScript
 

  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  

You need to login to post a comment.