title: Javascript : hide and show toggle button on <td> restores while page is loading
body: <p>I have a scenario like, there's a plain &lt;<strong>table</strong>&gt; &lt;<strong>td</strong>&gt; tags in my jsp page, between which I need to toggle hide-n-show, once click on a &lt;<strong>a href..</strong>&gt; hyperlink. I did the toggle using plain javascript function (not jQuery) and it's working okay.</p>
  <p>But the problem that I'm facing is, while doing some operations in &lt;<strong>td</strong>&gt;, it use to reload the page and hence it's resetting the toggled state.</p>
  <p>The code in jsp (with <em>custom-tag</em>) is :</p>
  <pre><code>&lt;a id=&quot;toggleLinkId&quot; href=&quot;#&quot; onclick=&quot;javascript:toggleTable();&quot; &gt;Toggle Table&lt;/a&gt;
      &lt;td colspan=&quot;2&quot; id=&quot;id1&quot; style=&quot;display: none&quot;&gt;
      &lt;query:SingleQueryRecord editUrl=&quot;&lt;%=editURL%&gt;&quot; extraparameters='&lt;%=searchURL%&gt;'/&gt;
      &lt;/td&gt;
      &lt;td colspan=&quot;2&quot; id=&quot;id2&quot; &gt;
      &lt;query:QueryDataTable editUrl=&quot;&lt;%=editURL%&gt;&quot; /&gt;
      &lt;/td&gt;
  </code></pre>
  <p>Here, once clicked in '<code>toggleLinkId</code>' link, it calls the javascript function '<code>toggleTable()</code>'.
  But after doing manipulations, it reloads and resets the toggled &lt;<strong>td</strong>&gt;, because of the ' <code>style=&quot;display: none&quot;</code> ' , which is required for the first time page load.</p>
  <p>The javascript I wrote is a simple one:</p>
  <pre><code>function toggleTable(){
      
      if( document.getElementById('id1').style.display == 'none' ){
         document.getElementById('id2').style.display = 'none';
         document.getElementById('id1').style.display = 'block';
       } else{
         document.getElementById('id1').style.display = 'none';
         document.getElementById('id2').style.display = 'block';
      }
      
  }
  </code></pre>
  <p>I hope I can state clearly my problem. If any suggestions you can give to retain the toggled state even after the page reloads, it will be really helpful.
  Thanks.</p>