X
HOME HTML CSS JAVASCRIPT SQL PHP JQUERY ANGULAR XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

jQuery scrollTop() Method

jQuery HTML/CSS Methods jQuery HTML/CSS Methods

Example

Return the vertical scrollbar position for a <div> element:

$("button").click(function(){
   alert($("div").scrollTop());
});

Try it yourself »

Definition and Usage

The scrollTop() method sets or returns the vertical scrollbar position for the selected elements.

Tip: When the scrollbar is on the top, the position is 0.

When used to return the position:
This method returns the vertical position of the scrollbar for the FIRST matched element.

When used to set the position:
This method sets the vertical position of the scrollbar for ALL matched elements.


Syntax

Return vertical scrollbar position:

$(selector).scrollTop()

Set vertical scrollbar position:

$(selector).scrollTop(position)

Parameter Description
position Specifies the vertical scrollbar position in pixels


Examples

Try it Yourself - Examples

Set the vertical scrollbar position
How to set the vertical scrollbar position for an element.


jQuery HTML/CSS Methods jQuery HTML/CSS Methods


Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB HOSTING

UK Reseller Hosting

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates FREE Website Templates Free HTML Templates

SHARE THIS PAGE

facebook