I’m trying to auto scroll to bottom by this method, but this is not working. i made a ul li from JavaScript. I want to scroll it to bottom. on button click its not working.
io.on("new_message",function(data){
console.log(data);
var html ="";
if(data.sender==sender)
{
html+= "<li class='liRight'>"+data.msg+"</li> ";
}
else{
html+= "<li class='lileft'>"+data.msg+"</li> ";
}
messagelist.innerHTML+=html;
Scrollltobottom ();
})
function Scrollltobottom ()
{
console .log("scroll fiucvtiopjhn");
messagelist.scrollTop = messagelist.scrollHeight;
}
2
Answers
Use
scrollIntoView
. Here is a minimal reproducable exampleenter code here