开发者

jQuery detecting elements added via ajax

The following does not respond when a select field with class='crit' is inserted in to the page via ajax once the page has loaded开发者_如何学Go, and is then changed. How can I make it do so?

$(".crit").click(function(){alert("hello")})


Use this:

$('.crit').live('click', function(e) {
    alert('hello');
});

A regular event is only bound to the currently existing elements. When using live() the event handler is bound to the document itself and thanks to event bubbling it doesn't no handlers have to be attached to the actual elements.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜