I have a% div of% with attribute chat-history
.
Through jQuery I insert information into the database and then refresh to display in the overflow-y:scroll
div. I need to update the div via Ajax request, it will focus on the last line of the scroll bar.
Here is an excerpt of the code that updates the div after inserting the data into the database.
function atualiza(){
$.get(''+ url +'/chat-history', function(result){
$('.chat-history').html(result);
})
setTimeout('atualiza()', 3000);
$('#message-to-send').val('');
$('#sendMessage').attr("disabled", false);
//neste momento a div chat-history que está com scroll deve ter seu foco na última linha
}
I tried
$('html, body').animate({ scrollTop: $('.chat-history').offset().bottom }, 300);
But I did not have the expected result