
Originally Posted by
Twey
Code:
for(var i = 1, btn; btn = document.getElementById("TT" + i); ++i)
btn.onmouseover = (function(i) {
return function(e) {
dropdownmenu(this, e || event, 'AA' + i);
};
})(i);
btn = null;
Your coding practices are mostly good, but you need to watch out for browser differences. Only IE uses
event, and it will leak if you leave btn trapped in the closure.
You've over thought this. Event is just fine in all modern browsers when used in the way it is in the code. It works out to:
HTML Code:
<li onmouseover="dropdownmenu(this, event, 'AA1');">
Which is fine. But, I think boogyman was onto something. However, you cannot just pass i to the assigned function that way. Here's one way:
Code:
for(var i=1; i<=6; i++)
document.getElementById('TT'+i).onmouseover = new Function("dropdownmenu(this, event, 'AA"+i+"');");
Bookmarks