title: Get iterator index into a onmousedown function
body: <p>I am trying to do a seemingly trivial thing, but I cant figure this out. I am iterating over items found by the <code>document.getElementByClassName</code> method. I am doing so with indices so I can keep track of some stuff, and I need that index inside the <code>onmousedown</code> events for that specific element, however I can't figure out to do so.</p>
  
  <pre><code>var items = document.getElementsByClassName("someClass");
  
      for (var i = items.length - 1; i &gt;= 0; i--)
      {
          items[i].onmousedown=function(){
              //This does not work:
              var index = i; //I need the i variable from the loop above in here.
              console.log(index);
              this.innerHTML = doSomeWorkWith(index);
          };  
  
      }
  </code></pre>
  
  <p>Anyone know how to do this? I have thought of adding it to the element itself so I can access a variable there, but I would prefere not to as it would clutter the html code.</p>