Event delegation and adding event handlers to new elements are
actually two different things.

The event delegation works without any changes. So if you put a
"click" event on a table and click a "td" then the table's click event
will be triggered too.

The automatic event handler adding uses the "live" and "die" functions:

  http://docs.jquery.com/Events

Karl Rudd

On Fri, Jan 23, 2009 at 10:11 AM, Sam H <samh1...@gmail.com> wrote:
>
> John Resig said of 1.3:
>
> "I only posted last week about how event delegation can help you to
> optimize your code and it looks like jQuery will do it for you now,
> which means that any event handlers you add to a group of elements
> will automatically be added to matching elements when you create
> them."
>
> Yet I'm not seeing this functionality.  Within my $(document).ready()
> func, I do this:
>
>  $('.do_it').click(function() { ...stuff... });
>
> Yet if I dynamically create new items using class="do_it", the above
> function is not automatically attached to them.  I have to once again,
> after dynamically creating new items, perform the $('.do_it').click()
> again.
>
> I thought 1.3 was supposed to eliminate this.  Am I doing something
> wrong?

Reply via email to