title: How to assign variable in passing multiple ID's in java script function?
body: <p>I try to pass two id's from my list to function, But my function unable to recognize the id's.</p>
  
  <p>My code as follow:</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;script language="javascript"&gt; 
  function toggle(id1, id2)   {    
  var ele = document.getElementById(id2);  
  var text = document.getElementById(id1);  
      if(ele.style.display == "block") {  
              ele.style.display = "none";
          text.innerHTML = "NDEM10K";
      }
      else {
          ele.style.display = "block";
          text.innerHTML = "NDEM10K";
      }
  } 
  &lt;/script&gt;
  &lt;/head&gt;
   &lt;body&gt;
   &lt;ol&gt;
      &lt;li&gt;
          &lt;a id="displayText" href="javascript:toggle(this.id);"&gt;NDEM10K&lt;/a&gt; 
          &lt;div id="toggleText" style="display: none" onclick="toggle(this.id);"&gt;
          &lt;ul&gt;
              &lt;li&gt;AP&lt;/li&gt;
              &lt;li&gt;UP&lt;/li&gt;
              &lt;li&gt;KA&lt;/li&gt;
              &lt;li&gt;An&lt;/li&gt;
              &lt;li&gt;ts&lt;/li&gt;
          &lt;/ul&gt;
              &lt;/div&gt;
      &lt;/li&gt;
  &lt;/ol&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>My function unable to recognise id's. So, I want to assign id to a variable.</p>
  
  <p>My Full code is here:</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  
  
  &lt;script language="javascript"&gt; 
  function toggle(id1,id2) {
      var ele = document.getElementById(id1);
      var text = document.getElementById(id2);
      if(ele.style.display == "block") {
              ele.style.display = "none";
          text.innerHTML = "NDEM10K";
      }
      else {
          ele.style.display = "block";
          text.innerHTML = "NDEM10K";
      }
  } 
  
  
  &lt;/script&gt;
  &lt;/head&gt;
   &lt;body&gt;
   &lt;ol&gt;
      &lt;li&gt;
          &lt;a id="displayText" href="javascript:toggle(this.id);"&gt;NDEM10K&lt;/a&gt; 
          &lt;div id="toggleText" style="display: none" onclick="toggle(this.id);"&gt;
  
          &lt;ul&gt;
              States
              &lt;li&gt;Andhra&lt;/li&gt;
              &lt;li&gt;Andhra&lt;/li&gt;
              &lt;li&gt;Andhra&lt;/li&gt;
              &lt;li&gt;Andhra&lt;/li&gt;
              &lt;li&gt;Andhra&lt;/li&gt;
          &lt;/ul&gt;
  
              &lt;/div&gt;
      &lt;/li&gt;
      &lt;li&gt;
          &lt;a id="dT" href="javascript:toggle(this.id);"&gt;NDEM50K&lt;/a&gt; 
          &lt;div id="tT" style="display: none" onclick="NDEM50K(this.id);"&gt;
  
          &lt;ul&gt;
              Districts
              &lt;li&gt;East Godavari&lt;/li&gt;
              &lt;li&gt;West Godavari&lt;/li&gt;
              &lt;li&gt;Krishna&lt;/li&gt;
              &lt;li&gt;Vishaka&lt;/li&gt;
              &lt;li&gt;Hyderabad&lt;/li&gt;
          &lt;/ul&gt;
  
              &lt;/div&gt;
      &lt;/li&gt;
      &lt;li&gt;
          &lt;a id="2dT" href="javascript:toggle(this.id);"&gt;NDEM2K&lt;/a&gt; 
          &lt;div id="2tT" style="display: none" onclick="NDEM2K(this.id);"&gt;
  
          &lt;ul&gt;
              Districts
              &lt;li&gt;Hyderabad&lt;/li&gt;
              &lt;li&gt;Kakinada&lt;/li&gt;
              &lt;li&gt;Rajahmundry&lt;/li&gt;
              &lt;li&gt;Vishaka&lt;/li&gt;
              &lt;li&gt;Mumbai&lt;/li&gt;
          &lt;/ul&gt;
  
          &lt;/div&gt;
      &lt;/li&gt;
  
  &lt;/ol&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>