- I have a basic
conversation-body
element with the propertyoverflow: auto
. - I am trying to make this div scroll to the top by its own height.
This is what I have tried so far:
//accessing the element
var parent = document.getElementsByClassName('conversation-body')[0];
//getting the height
var parentHeight = parent.getBoundingClientRect().bottom - parent.getBoundingClientRect().top;
//attempting to scroll it up
parent.scrollTop += parentHeight;
- It does work, but there is some extra space at the top.
- Any idea why this is happening?
- Here is the website link where you can try the code in the console.