[jQuery] Re: Attaching events to dynamic DOM IDs

2007-12-23 Thread Rabbit
Wow. Talking about mind-blowing. I read through the dummy article and I will definitely be reading it again tomorrow. And probably the next day, too. Thank you so much for taking the time to explain and share; I appreciate it! - Daniel --- On Dec 22, 5:18 pm, "Michael Geary" <[EMAIL PROTECTED]

[jQuery] Re: Attaching events to dynamic DOM IDs

2007-12-22 Thread Michael Geary
In fact, it is a closure, and it works very much like closures in Ruby and other languages. Keep in mind that a JavaScript object is reference counted and remains in existence as long as there are any references to the object. Once there are no more references to an object, it becomes available f

[jQuery] Re: Attaching events to dynamic DOM IDs

2007-12-22 Thread Rabbit
Hmm... I didn't realize this until I was falling asleep last night, but what you've demonstrated is similar to a closure in Ruby, except not. My understanding of what you said is something along the lines of... An argument to a method becomes a local variable in that method and is _retained_. But

[jQuery] Re: Attaching events to dynamic DOM IDs

2007-12-22 Thread Rabbit
> On Dec 22, 12:55 am, "Michael Geary" <[EMAIL PROTECTED]> wrote: > By moving this code into a function, a new variable "i" is created each time > the function is called. You no longer have all the code sharing a single > variable - each instance of the function gets its own. Ah, brilliant. I see

[jQuery] Re: Attaching events to dynamic DOM IDs

2007-12-22 Thread Michael Geary
As an alternative to the other solution you posted, here is how you can do it with code more like the code below: for(var i = 0; i < 30; i++) clicker( i ); function clicker( i ) { jQuery('#day_' + i).click(function() { console.log('i is ' + i); jQuery('#day_' + i + '_modal').jqmShow(

[jQuery] Re: Attaching events to dynamic DOM IDs

2007-12-22 Thread Stefan Petre
for(var i = 0; i < 30; i++) { jQuery('#day_' + i).click(function() { jQuery('#' + this.id+ '_modal').jqmShow(); }); } maybe it works this way 2007/12/22, Rabbit <[EMAIL PROTECTED]>: > > > The following code: > > for(var i = 0; i < 30; i++) { > jQuery('#day_' + i).click(function() { > c

[jQuery] Re: Attaching events to dynamic DOM IDs

2007-12-22 Thread Rabbit
I got around it by using some jQuery's each and selector methods. jQuery('.calendar_cell_active').each(function() { $('#' + $(this).attr('id') + '_modal').jqm(); $(this).click(function() { $('#' + $(this).attr('id') + '_modal').jqmShow(); }); }); It's a little bit more confusing, but