obj is the <div> id

<script type='text/javascript'>
function toggle(obj){
   var e=document.getElementById(obj);
      if(!e)return true;
      if(e.style.display=="none"){
         e.style.display="block"
      } else {
         e.style.display="none"
      }return true;
}
</script>

in your markup

<a href='#' onClick="toggle('mydiv')">Toggle</a>
<div id='mydiv' style="display:none">
  Lorem ipsum dolor sit amet, consectetur
  adipisicing elit, sed do eiusmod tempor
  incididunt ut labore et dolore magna
  aliqua. Ut enim adminim veniam.
<div>

EDIT: sorry for the wrong code. :D its now updated

3 Responses to “Toggle, hide, collapse your html content”

  1. paminggalan Says:

    thanks for the comment. :D i’ve edited my post :D

  2. Jay Says:

    what if i only want the a div close if the word-count of a post is less then 400 words?


Leave a Reply