You meant 5, not 4 :-)
On Mon, Sep 14, 2009 at 11:31 AM, Kelvin Luck <[email protected]> wrote:
>
> for (var i=0; i<5; i++) {
> $('item#' + i).click(
> function()
> {
> alert(i);
> }
> );
> }
>
> People expect each item to alert it's own number but they will all alert 4
> as that is the value of i by the time the click handler is actually
> executed.
>
> Hope that helps,
>
> Kelvin :)
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"jQuery Development" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/jquery-dev?hl=en
-~----------~----~----~----~------~----~------~--~---