0

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?

2

1 Answer 1

2

The scrollTop property tells you the vertical scroll position:

document.getElementById("yourButton").onclick = function() {
   alert(document.getElementById("yourDiv").scrollTop); 
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.