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.
精彩评论