title: JavaScript - For loop button onclick - identify which button
body: <p>I'm creating 5 divisions in for loop, each division have one image and one button.
  Button's action is to perform like/vote. But, the images and buttons being in for loop, i don't know which button is linked with which image id. So that i can put it into database that image have been voted.</p>
  
  <pre><code>&lt;%
  for(until resultSet has next){
      %&gt;
          &lt;img id="img" src="resultsetValue" /&gt;
          &lt;button id="btn" &gt;VOTE&lt;/button&gt;
      &lt;%
  }
  %&gt;
  </code></pre>
  
  <p>In JavaScript file:</p>
  
  <pre><code>document.getElementById("btn").onclick = function(){
      //WHICH IMAGE NEEDS VOTE NOW
  }  
  </code></pre>
  
  <p>Now, if you see, i gave them id's too. An id must be unique to each element, but i gave id in for loop, which makes every image and every button have same id. How can i resolve this or is it ok?</p>
  
  <p>i don't want to use jQuery, i have to learn it yet.</p>