jQuery click function is not working on data returned from ajax
I am working on a feature like status message update.. the user can update is status message without page refresh and the new message will be displayed once the user clicks the button and the other users can comment on the status message. The problem I am facing is, when the user submits the data, the new status message will be displayed and when I click the comment button the comment box is showing, but when I reload the page and click开发者_开发知识库 comment button the comment box is displaying...
When you bind the event, the ajax result html isn't there yet.
jQuery has a simple way of dealing with this: Use live
(or delegate
on 1.4.2).
For example (from the above links):
instead of:
$('.clickme').click(function() {
// Bound handler called.
});
write:
$('.clickme').live('click', function() {
// Live handler called.
});
精彩评论