I have one button in a div tag. That div tag also has a vertical scroll bar.
If I scroll that bar and click on the button which is inside that div, it should return the scroll position as an alert message.
How to do that using JavaScript?
I have one button in a div tag. That div tag also has a vertical scroll bar.
If I scroll that bar and click on the button which is inside that div, it should return the scroll position as an alert message.
How to do that using JavaScript?
Share Improve this question edited Sep 6, 2011 at 9:27 Py. 3,6091 gold badge36 silver badges55 bronze badges asked Sep 6, 2011 at 7:40 SwaroopSwaroop 211 gold badge3 silver badges7 bronze badges 2- 1 You could do this pretty easily with jquery. Is that an option? – Matt Commented Sep 6, 2011 at 7:41
- Possible duplicate of retrieve Scrollbar position with javascript – Félix Adriyel Gagnon-Grenier Commented Dec 31, 2015 at 11:21
1 Answer
Reset to default 2The scrollTop
property tells you the vertical scroll position:
document.getElementById("yourButton").onclick = function() {
alert(document.getElementById("yourDiv").scrollTop);
}