var product=””;
for (var i=0; i<10; i++)
{
product+=””+i+””;
$(“#”+i).hover(function()
{
alert(i);
});
}
product variable is able to generate the desired output with the div ids ,but when I m moving my mouseover those divs, that mouseover function(from jquery) is not working/called.
Please help
Thanks
Dave
Why not do it like this:
A few comments:
iwill have the value from the last iteration in any closure (i.e. everyalert(i)will alert10) (See JavaScript Closures for Dummies – Example 5). That is why I usebind()here. The eventsmouseenterandmouseleaveare the ones,hover()binds the handler to. And to overcome the problem withi, I pass the value ofias event data.