Please note, this is a STATIC archive of website www.w3schools.com from 05 May 2020, cach3.com does not collect or store any user information, there is no "phishing" involved.
THE WORLD'S LARGEST WEB DEVELOPER SITE

jQuery scrollLeft() Method

❮ jQuery HTML/CSS Methods

Example

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

$("button").click(function(){
  alert($("div").scrollLeft());
});
Try it Yourself »

Definition and Usage

The scrollLeft() method sets or returns the horizontal scrollbar position for the selected elements.

Tip: When the scrollbar is on the far left side, the position is 0.

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

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


Syntax

Return horizontal scrollbar position:

$(selector).scrollLeft()

Set horizontal scrollbar position:

$(selector).scrollLeft(position)

Parameter Description
position Specifies the horizontal scrollbar position in pixels

Try it Yourself - Examples

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


❮ jQuery HTML/CSS Methods