title: Jquery - Pass data to inline functions
body: <p>This is probably really simple, and the answer is probably really obvious, but I'm drawing a blank here.</p>
  
  <p>I have an array of HTML elements that I am binding the .hover() event to. I need to know what array index was used by the event.</p>
  
  <p>So let's say element[7] is hovered over, how do I pass the number 7 to that function?</p>
  
  <p>Here is what I am using:</p>
  
  <pre><code>for (i=0; i&lt;statecount; i++) {
      $("#"+imagemap[i][0]).hover(function() {
          // Mouse enters HTML element
  
          alert(i); 
  
          // "i" returns 15, which makes sense because "i" 
          // has changed since this function was defined.
      });
  }
  </code></pre>