title: How to tell JavaScript function which id to get from a PHP while loop?
body: <p>I have a JavaScript function which toggles a div to show/hide, it works if I just have the one link that toggles the single div. But I have a while loop which creates several of these links and div, one for each row. But only the first link works. I can add a $ at end of my id for both the toggle link and div, how do I tell JavaScript to look for this variable?</p>
  
  <p>JavaScript:</p>
  
  <pre><code>$(function(){
      var id = document.getElementById();
      $('#toggleDiv').click(function(){
          $('#targetDiv').toggle();
      });
  });
  </code></pre>
  
  <p>PHP:</p>
  
  <pre><code>echo "&lt;a href=\"javascript:void(0);\" id=\"toggleDiv$ctr\"&gt;;
  echo "&lt;div id=\"targetDiv$ctr\" style=\"display:none;\"&gt;";
  </code></pre>
  
  <p>As you can see, the $ctr helps individualize each link and div, but I need java to identify which #toggleDiv is being clicked, allowing it to toggle the correct #targetDiv.</p>
  
  <p>Any help?</p>