---
title: "scrollLeft method do in jQuery"  
description: "scrollLeft method do in jQuery"  
author: "Ethan Karla"  
published: 2021-07-29  
updated: 2023-06-13  
canonical: https://www.mindstick.com/forum/156677/scrollleft-method-do-in-jquery  
category: "jquery"  
tags: ["jquery"]  
reading_time: 2 minutes  

---

# scrollLeft method do in jQuery

What does the scrollLeft [method](https://www.mindstick.com/forum/166/webservice-method) do in jQuery?

\

## Replies

### Reply by SundarLal Sharma

In jQuery, the **scrollLeft()** method is used to get or set the horizontal scroll position of an element. It can be used to manipulate the scroll position of an element horizontally.

To get the current horizontal scroll position of an element, you can use the **scrollLeft()** method without any arguments:

```javascript
var scrollPosition = $(element).scrollLeft();
```

To set the horizontal scroll position of an element, you can pass the desired scroll value as an argument to the **scrollLeft()** method:

```javascript
$(element).scrollLeft(scrollValue);
```

Here, **element** refers to the target element on which you want to manipulate the scroll position, and **scrollValue** is the desired horizontal scroll position you want to set.

By using the **scrollLeft()** method, you can control and modify the horizontal scroll position of an element dynamically within your jQuery code.

### Reply by Aryan Kumar

The scrollLeft() method in jQuery is used to set or return the horizontal scroll position of the selected elements. When the scrollbar is on the left, it specifies the position 0. To return the position, no parameters are required. To set the position, a single parameter is required, which is the number of pixels to scroll the element horizontally.

Here is an example of how to use the scrollLeft() method to set the horizontal scroll position of an element to 100 pixels:

Code snippet

```plaintext
$('element').scrollLeft(100);
```

Here is an example of how to use the scrollLeft() method to return the horizontal scroll position of an element:

Code snippet

```plaintext
var scrollPosition = $('element').scrollLeft();
```

The scrollPosition variable will now contain the horizontal scroll position of the element in pixels.

The scrollLeft() method can be used to scroll elements horizontally in both directions. To scroll to the left, a negative value can be passed to the method. To scroll to the right, a positive value can be passed to the method.

The scrollLeft() method can also be used to scroll elements horizontally by a specific amount. For example, the following code will scroll the element 10 pixels to the left:

Code snippet

```plaintext
$('element').scrollLeft(-10);
```

The scrollLeft() method is a powerful tool that can be used to control the horizontal scroll position of elements in a web page.


---

Original Source: https://www.mindstick.com/forum/156677/scrollleft-method-do-in-jquery

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
