Reputation: 2533
I have the following AJAX call to a file:
$.ajax({
url: readfile.txt,
cache: false,
success: function(data){
$('#content').html(data);
};
});
It appends the contents of the readfile.txt to the #content div. This is working properly.
What I want to do, is to scroll to the bottom of the div, every time the content is changed. Currently I have the following:
$('#content').bind('DOMNodeInserted DOMSubtreeModified', function(){
$('#content').animate({scrollTop: $('#content').prop("scrollHeight")}, 500);
});
The animate function is working properly, however it isn't being triggered when the html of the #content div is changed. Is there a better way to listed for html change events?
Thanks in advance.
Upvotes: 0
Views: 61
Reputation: 3811
Just add the animation to your success callback
$.ajax({
url: readfile.txt,
cache: false,
success: function(data){
$('#content').html(data).animate({scrollTop: $('#content').prop("scrollHeight")}, 500);
};
});
Upvotes: 3