I'm trying to load more messages from database after I scroll to the top of the div:
$('#chatbox').on('scroll', function(){
console.log($('#chatbox').scrollTop());
if ($('#chatbox').scrollTop() == 0) {
var count = parseInt($('#chatroom-table tr').length) + 10;
$.get('get_chatroom_messages/' + count, function(responseData) {
$('#chatroom-div').replaceWith(responseData);
});
}
});
This works great - once. After the replaceWith() is called for the first time, the scroll() method stops working. I tried rebinding the event, but with no success.
I thought that the .on method takes care of elements that are not yet created / are replaced.
EDIT:
I also tried this, but the event doesn't even fire at all then:
$('body').on('scroll', '#chatbox', function(){
....
});
EDIT2:
ehhh, I'm marking myself as a duplicate: Events not registering after replaceWith