23369
Views
3
Comments
Make a Div scroll to bottom

I'm trying to make a div with Chat Messages scroll to the last message when we add the last message on the table with those messages to be displayed.

Can someone help me?

I already tried with javascript, but it is not recognizing the div to make something like this:

var element = document.getElementById("yourDivID");
    element.scrollTop = element.scrollHeight;
2016-04-21 20-09-55
J.
 
MVP

what do you mean it's not recognizing the div?


do you create the javascript via an expression?

then it would be something like: 

"

var element = document.getElementById('#" + yourDiv.Id + "');

element.scrollTop = element.scrollHeight;

"

2016-02-19 12-35-00
Nelson Mendes

J. wrote:

what do you mean it's not recognizing the div?


do you create the javascript via an expression?

then it would be something like: 

"

var element = document.getElementById('#" + yourDiv.Id + "');

element.scrollTop = element.scrollHeight;

"

Yeah J i want that exactly, im already using that piece of code, but it seems that the "element.scrollTop = element.scrollHeight;" isn't doing anything....

That worked with you?


2016-04-21 20-09-55
J.
 
MVP

not sure,

try using the jquery variant:

$('#div1').scrollTop($('#div1')[0].scrollHeight);

otherwise provide a live demo so we can check what might go wrong (aka personalcloud example)


Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.