jQuery .scroll() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Browser Events

Definition

.scroll() is jQuery’s legacy shorthand (since 1.0) for binding or triggering the browser scroll event on window or a scrollable element. It is deprecated since 3.3 but still works in jQuery 3.x. Prefer .on("scroll") / .trigger("scroll").

Syntax

Start with these common calls. Keep them short and readable.

jQuery
// Deprecated (since 3.3) — still works in jQuery 3.x
$("#target").scroll(function () {
  // scroll position changed
});

$("#target").scroll(); // trigger

// Modern replacements
$("#target").on("scroll", handler);
$("#target").trigger("scroll");
CallWhat it does
Targetwindow or a scrollable element
handlerfunction(event)
eventDataExtra data as event.data
ThrottleLimit how often expensive work runs

Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.

Parameters

ParameterDescription
Step 1Bind with $("#el").scroll(handler) (legacy) or .on("scroll", handler) (preferred).
Step 2Optionally pass eventData: .scroll(data, handler) → .on("scroll", data, handler).
Step 3Trigger with no-arg .scroll() (legacy) or .trigger("scroll") (preferred).

Return Value

Return ValueDescription
jQuery objectMost setters and traversing helpers return the jQuery collection so you can chain more methods.

jQuery Examples

Example 1 — Basic $("#target").scroll(fn)

Canonical legacy pattern: append a message each time scroll fires.

jQuery
$("#target").scroll(function () {
  $("#log").append("Handler for scroll called. ");
});
Try It Yourself

How It Works

  1. Bind. .scroll(fn) on #target registers a handler.
  2. Delegate. jQuery routes it to .on("scroll", fn) internally.
  3. Scroll. Wheel, bar, keys, or touch all fire the same event.

Example 2 — .scroll(eventData, handler)

Pass extra data (since 1.4.3). Modern form: .on("scroll", data, fn).

jQuery
$("#target").scroll({ label: "panel" }, function (event) {
  $("#out").text(
    event.data.label + ": " + $(this).scrollTop() + "px"
  );
});
Try It Yourself

How It Works

  1. Data. The object becomes event.data inside the handler.
  2. Scroll. Position change fires the event.
  3. Read. Use event.data.label plus .scrollTop().

Example 3 — No-arg .scroll() Trigger

Fire the event programmatically. Prefer .trigger("scroll") today.

jQuery
$("#target").scroll(function () {
  $("#out").text("Handler for scroll called.");
});

$("#run").on("click", function () {
  $("#target").scroll(); // legacy trigger
});
Try It Yourself

How It Works

  1. Bind. The handler is registered first.
  2. Click. No-arg .scroll() triggers the event.
  3. Run. Bound handlers execute immediately.

Frequently Asked Questions

The .scroll() method has two roles. With a handler — .scroll(handler) or .scroll(eventData, handler) — it binds a function that runs when the user scrolls a matched element. Bind on $(window) for page scroll or on an overflow element for container scroll. With no arguments — .scroll() — it triggers the scroll event. Both forms exist since jQuery 1.0; binding is deprecated since 3.3.
Deprecated, not removed. Binding signatures are deprecated since jQuery 3.3 — use .on("scroll", handler) instead. Unlike .error(), which was removed in jQuery 3.0, .scroll() still works in jQuery 3.x. Prefer .trigger("scroll") over no-arg .scroll() for clarity.
.scroll(handler) registers a callback and does not fire immediately. .scroll() with no arguments triggers the scroll event on each matched element — the same as .trigger("scroll"). Bind on the element whose scrollTop or scrollLeft actually changes.
.scroll() is an event shorthand — it binds or triggers the scroll event. .scrollTop() gets or sets the vertical scroll position. They are not interchangeable: binding .scroll() does not move the page, and .scrollTop(100) does not register a listener.
Replace .scroll(fn) with .on("scroll", fn). Replace .scroll(data, fn) with .on("scroll", data, fn). Replace no-arg .scroll() with .trigger("scroll"). Cleanup with .off("scroll"). Under the hood, .scroll(handler) already delegates to .on("scroll").
Yes. Scroll can fire dozens of times per second. Wrap progress bars and sticky checks in throttle (or debounce when you only need the final position), whether you use legacy .scroll(fn) or modern .on("scroll", fn).

Next: Effects Methods

Continue with attribute helpers like .attr() and .prop().

Effects Methods tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful