I'm having trouble ensuring that my chatbox's scrollbar automatically starts at the bottom so that new messages are visible without needing to scroll down. The current code I have in JQuery is not achieving this desired behavior.
$('#chatbox').each(function(){
$(this).scrollTop($(this).prop('scrollHeight'));
});
How can I make sure the scrollbar always remains at the bottom of the chatbox for a seamless user experience?
Update: I have tried using the following code, which positions the scrollbar around the middle of the chatbox but doesn't keep it at the bottom.
$('#chatbox').animate({
scrollTop: $('#chatbox').height()}, 0
);