jQuery Tutorial

jQuery scrollLeft() Method With Syntax and Example

Table of Contents

  • What is scrollLeft method in jQuery?
  • Syntax of scrollLeft method in jQuery
  • Example of jQuery scrollLeft method

What is scrollLeft method in jQuery?

For the selected components, the scrollLeft() method sets or returns the horizontal scrollbar position 

The position of the scrollbar is 0 when it is on the far left side.

When used to revert to the previous position:

This method returns the scrollbar's horizontal position for the FIRST matched element.

When you use it to set the position, it looks like this:

This method adjusts the scrollbar's horizontal position for ALL matched elements.

Syntax of scrollLeft method in jQuery

  • Return the horizontal scrollbar to its previous position:

$(selector).scrollLeft()

  • Set horizontal scrollbar position:

$(selector).scrollLeft(position)

Example of jQuery scrollLeft method

For a

element, get the horizontal scrollbar position:
$("button").click(function(){
  alert($("div").scrollLeft());
});
Did you find this article helpful?