Posted By

cfleschhut on 08/14/10


Tagged

javascript closure events


Versions (?)

JavaScript Event Handler Closure


 / Published in: JavaScript
 

URL: http://jsfiddle.net/YwtEz/

  1. window.onload = function() {
  2. var ul = document.getElementById("foo");
  3. var lis = ul.getElementsByTagName("li");
  4. for(var i=0; i<lis.length; i++) {
  5. lis[i].onmouseover = function(x) {
  6. return function() {
  7. console.log(x);
  8. }
  9. }(i);
  10. }
  11. };

Report this snippet  

You need to login to post a comment.