title: Showing and hiding dynamically generated ID's with javascript
body: <p>The code below is showing and hiding div content with <code>dynamically generated id's</code> like <code>div_1, div_2</code> from <code>div id</code>, all seems working fine except that it requires to hide one div content at a time like clicking div_1 should open its content and on clicking div_2 should hide div_1. please help me sort out this problem.</p>
  
  <pre><code>echo "&lt;span class='bold'&gt;&lt;a name='form_a_$group_seq' href='#div_$group_seq' id='form_a_$group_seq' value='1' " .
  "onclick='return divclick(this,\"div_$group_seq\");'";
   if ($display_style == 'block') echo "clicked";
   echo "&lt;b&gt;" . xl_layout_label($group_name) . "&lt;/b&gt;&lt;/a&gt;&lt;/span&gt;\n";
  
   echo "&lt;div id='div_$group_seq' class='section' style='display:$display_style;'&gt;\n";
   echo " &lt;table border='0' cellpadding='0'&gt;\n";
   $display_style = 'none';
  }
  else if (strlen($last_group) == 0) {
  echo " &lt;table border='0' cellpadding='0'&gt;\n";
  }
  </code></pre>
  
  <p>Below is the javascript to make the code workable. but its showing or hiding all the div contents at a time.</p>
  
  <pre><code>function divclick(a, divid) {
      var divstyle = document.getElementById(divid).style;
      if ( divstyle.display == 'none' ) {
          divstyle.display = 'block';
      } else {
          divstyle.display = 'none';
      }
      return true;
  }
  </code></pre>
  
  <p>this is a piece of updated html code that's what browser is rendering.</p>
  
  <pre><code>&lt;div class='container2'&gt;&lt;ul class='taby'&gt;&lt;li class='dropown'&gt;&lt;a name='form_a_1' href='#div_1'   id='form_a_1' value='1' onclick='return divclick(this,"div_1");'&gt;Who&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;
  &lt;div id='div_1' class='section'&gt;
  &lt;table border='0' cellpadding='0'&gt;
  &lt;div id='div_2' class='section'&gt;
  &lt;table border='0' cellpadding='0'&gt;
  &lt;div id='div_3' class='section'&gt;
  &lt;table border='0' cellpadding='0'&gt;
  </code></pre>