jQuery binding live events

被刻印的时光 ゝ 提交于 2019-12-11 14:47:26

问题


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


回答1:


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



来源:https://stackoverflow.com/questions/3400626/jquery-binding-live-events

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!