Sometimes, we want to get the scroll position of div with “overflow: auto” with JavaScript.
In this article, we’ll look at how to get the scroll position of div with “overflow: auto” with JavaScript.
How to get the scroll position of div with “overflow: auto” with JavaScript?
To get the scroll position of div with “overflow: auto” with JavaScript, we use the scrollTop
property.
For instance, we write
const scrollTop = document.getElementById("box").scrollTop;
to select the scrollable div with getElementById
.
Then we get its scroll position with scrollTop
.
Conclusion
To get the scroll position of div with “overflow: auto” with JavaScript, we use the scrollTop
property.