On May 30, 12:08 am, truent <[EMAIL PROTECTED]> wrote:
> Im using $(document).ready to bind an onsubmit and onclick event to 2
> elements of my form.  Either of these events fires separately with no
> problem.  However, when the onsubmit injects html into a div on page,
> and I then attempt to click on one of the newly injected elements
> expecting the onclick to fire, it doesnt.  Is there something about
> the dom not being refreshed or  $(document).ready not able to bind
> elements after the page has been loaded and new html injected?  Can I
> update the dom?  is there an even other than .ready to bind to?

You note that you have bound onclick to two elements of your form but
not that you've attempted to bind it to anything else.  I'm not sure
what events you intend to be attached to the new elements.

However, $(document).ready() only fires after the document initially
loads.  If you want to bind events DOM elements that are generated or
included after the fact, you need to either bind something to a parent
element and catch the event as it bubbles up (event delegation[1]) or
use a plugin to do that for you.  jQuery Live Query[2] is a easy,
sound way to handle that.

~Pyro

[1] http://www.learningjquery.com/2008/03/working-with-events-part-1
[2] http://brandonaaron.net/docs/livequery/

Reply via email to