开发者

jQuery detecting elements added via ajax

开发者 https://www.devze.com 2023-02-27 13:47 出处:网络
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?

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

精彩评论

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