开发者

jQuery binding live events

开发者 https://www.devze.com 2023-01-10 06:23 出处:网络
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 execut

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 el开发者_如何学Cements, 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,

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

0

精彩评论

暂无评论...
验证码 换一张
取 消