jQuery scrollTop() method
Example
Return
The vertical scrollbar position of an element:
$
(
"
button
"
)
.
click
(
function
(
)
{
alert
(
$
(
"
div
"
)
.
scrollTop
(
)
)
;
}
)
;
Try it »
Definition and Usage
The scrollTop() method sets or returns the vertical scrollbar position of the selected elements.
**Tip:** When the scrollbar is at the very top, the position is 0.
**When used to return the position:
**This method returns the vertical scrollbar position of the first matched element.
**When used to set the position:
**This method sets the vertical scrollbar position of all matched elements.
Syntax
Return the vertical scrollbar position:
$(
selector
).scrollTop()
Set the vertical scrollbar position:
$(
selector
).scrollTop(
position
)
| Parameters | Description |
|---|---|
| position | Specifies the vertical scrollbar position in pixels. |
More examples
Set the vertical scrollbar position
How to set the vertical scrollbar position of an element.
jQuery HTML/CSS methods