0

I am having troubles binding live events to dynamically created content.

I have a page which loads a html page through an ajax call. The loaded html page contains some javascript which is then executed. The executed javascript creates some elements.

I want to bind a click event handler to those elements, however after binding them (using .live, .delegate and plain old .click) nothing happens after clicking on them.

I am able to retrieve the contents of the elements (by calling .html) but I can't bind events on them for some reason...

I have also tried adding onclick="alert('test');" to the elements before spitting them out through javascript but to no avail...

Anyone know of a solution?

Thanks

John
  • 1
  • When are you making the event bindings? You need to be sure that the bindings are executed **after** the content is created by your javascript. If you're using chrome, inspect one of those elements: see if any event listeners are bound to it. I don't know if firebug or the IE console does this as well, I've only been using chrome lately. – godheadatomic Aug 03 '10 at 20:50
  • @Nick Craver - ah, I missed that somehow! Nevermind :) – godheadatomic Aug 03 '10 at 20:53

1 Answers1

0

John,

take a look at the .livequery() plugin. this will give you a full range that includes the .live() event plus other callback scenarios.

http://docs.jquery.com/Plugins/livequery

jim

jim tollan
  • 22,305
  • 4
  • 49
  • 63