I did. I meant '#item' + i and not 'item#' + i too! Sorry for the  
confusion...

On Mon, 14 Sep 2009 11:38:16 +0100, Andrea Giammarchi  
<andrea.giammar...@gmail.com> wrote:

> You meant 5, not 4 :-)
>
> On Mon, Sep 14, 2009 at 11:31 AM, Kelvin Luck <kel...@kelvinluck.com>  
> 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 jquery-dev@googlegroups.com
To unsubscribe from this group, send email to 
jquery-dev+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/jquery-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to