title: How to Toggle a div's visibility by using a button click
body: <p>Below is my javascript code which i used to show a <code>div</code> when clicked on a <code>button</code>. </p>
  
  <p>How can I hide it when clicked again? And then on clicking it, <code>div</code> should be visible again?</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  var _hidediv = null;
  function showdiv(id) {
      if(_hidediv)
          _hidediv();
      var div = document.getElementById(id);
      div.style.display = 'block';
      _hidediv = function () { div.style.display = 'none'; };
  }
  &lt;/script&gt;
  </code></pre>