jQuery .one() Method

Beginner
6 min read
Updated: Oct 2026
5 examples
Live preview

What Is .one()?

.one(events [, selector] [, data], handler) is like .on(), except the handler is unbound after its first run on that element for that event type (since 1.1; full .on()-style signatures since 1.7).

Remember
$("#foo").one("click", function () {
  alert("This will be displayed only once.");
});

// Equivalent idea:
$("#foo").on("click", function (event) {
  alert("This will be displayed only once.");
  $(this).off(event);
});
NeedUse
One-shot handler.one()
Repeat handler.on()
Manual remove.off()
Fire for testing.trigger()
Fire without bubbling.triggerHandler()

How to Use .one()

Use the same patterns as .on() when you only want the first fire.

  1. Select the element(s) that should react once.
  2. Call .one(events, handler) (or with selector / data like .on()).
  3. First matching event runs the handler.
  4. jQuery unbinds that handler for that element and event type.
  5. Further matching events on that element do nothing for that binding.
FormSinceRole
.one(events [, data], handler)1.1Direct one-shot bind
.one(events [, selector] [, data], handler)1.7Delegated one-shot bind
.one(eventsMap [, selector] [, data])1.7Object map of event → handler

Pseudocode

Pseudocode
attach handler like .on(...)

when EVENT fires on ELEMENT (or matching descendant):
    run HANDLER once
    unbind this handler for ELEMENT + EVENT type

later same EVENT on same ELEMENT:
    this binding does not run again

note:
    multiple event types → once per type

Cheat Sheet

Quick facts for one-shot handlers.

TopicDetail
ReturnsjQuery (chainable)
Since1.1 · delegation / map 1.7
LimitOnce per element per event type
vs .on()Same API, auto-unbind after first run
Multi-typeEach listed type gets its own “once”
Per elementEach matched element has its own counter
Remove earlyStill possible with .off() before it fires

Live Preview

Click the target once — then again. Compare with a normal .on() bind.

Run a bind style, then click / hover the target.

Log
Ready — Run “one”, then click Target twice.

jQuery Examples

Short, copy-ready snippets. Prefer .one() over manual .off(event) for simple one-shot cases.

Example 1 — One-Time Click

First click runs the handler; later clicks do nothing.

jQuery
$("#foo").one("click", function () {
  $("#out").text("Fired once — click again does nothing.");
});
Try It Yourself

How It Works

  1. Bind. .one("click", …) attaches a temporary handler.
  2. First. The click runs your function.
  3. Unbind. jQuery removes that click handler automatically.
  4. Later. Further clicks find nothing from this binding.

Example 2 — Once Per Element

Each matched element gets its own independent one-shot.

jQuery
var n = 0;
$(".box").one("click", function () {
  var index = $(".box").index(this);
  $("#out").text(
    "Box #" + index + " clicked. Total unique: " + (++n)
  );
});
Try It Yourself

How It Works

  1. Many. Each .box receives its own .one() binding.
  2. First per box. That box’s handler runs and unbinds.
  3. Siblings. Other boxes still have their unused shot.
  4. Count. Shared counter tracks how many unique boxes fired.

Example 3 — Multiple Event Types

Once per type — hover and click can each fire once.

jQuery
var n = 0;
$(".target").one("click mouseenter", function (event) {
  $("#out").text(++n + " · " + event.type);
});
Try It Yourself

How It Works

  1. Two types. Space-separated names create two one-shot slots.
  2. Enter. First mouseenter runs and clears that type.
  3. Click. First click can still run afterward.
  4. Repeat. A second enter or click of the same type does nothing.

Example 4 — Delegated .one()

Same API as delegated .on() — but the root’s binding is spent after the first match.

jQuery
$("#list").one("click", "button.item", function () {
  $("#out").text("Once: " + $(this).text());
});
Try It Yourself

How It Works

  1. Root. Listener sits on #list with a child selector.
  2. Match. First bubbled click from button.item runs the handler.
  3. Once. The limit is on #list (the bound element), not each child.
  4. Later. Other items no longer trigger this binding.

Example 5 — Equivalent .on() + .off(event)

Official idea: .one() is sugar for unbinding inside the handler.

jQuery
$("#a").one("click", function () {
  $("#out").text("via .one()");
});

$("#b").on("click", function (event) {
  $("#out").text("via .on() + .off(event)");
  $(this).off(event);
});
Try It Yourself

How It Works

  1. One. Auto-removes after the first run.
  2. Manual. .off(event) removes the current event’s handlers on this.
  3. Same effect. Both patterns are one-shot for that type.
  4. Prefer. .one() when you do not need custom cleanup logic.

Edge Cases & Pitfalls

Common surprises with one-shot handlers.

types

Multi-type ≠ once total

.one("click mouseenter", fn) can still run twice — once per type.

elements

Each element has its own “once”

Clicking box A does not spend box B’s one-shot handler.

trigger

.trigger() also spends the shot

A programmatic trigger counts as the first invocation and unbinds afterward.

rebinding

Need another shot? Bind again

Call .one() again (or use .on()) if the action should be allowed later.

Browser Support

.one() has been part of jQuery since 1.1 (delegation and events-map forms since 1.7). It works wherever your loaded jQuery version runs.

✓ Stable · jQuery 1.1+

.one()

Works in every browser that runs your loaded jQuery version. Prefer a current jQuery 3.x build for modern projects.

100% With jQuery events
Google Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Internet Explorer IE 6+ · Legacy environments
Full support
Opera All modern versions
Full support
.one() Universal

Bottom line: Production-ready. Use .one() for first-interaction handlers; use .on() when the handler must keep firing.

Performance Notes

ApproachCostBest for
.one() on a few elementsTinyFirst-click / init-on-interact
Leaving forever .on() you meant onceExtra work on later eventsPrefer .one() to auto-clean
Many one-shots on huge listsHigher bind costConsider one delegated .on() with a “done” flag

.one() is cheap and self-cleaning. For thousands of items, one delegated handler with your own “already handled” check can be leaner.

Key Takeaways

  • Role: attach a handler that auto-removes after its first run.
  • Scope: once per element per event type — not once for the whole page.
  • API: same shapes as .on() (direct, delegated, data, maps).
  • Equiv: .on() + $(this).off(event) after the first run.

One line: .one() is .on() that unbinds itself after the first fire.

Frequently Asked Questions

.one() attaches a handler that runs at most once per matched element per event type. After the first run, jQuery unbinds that handler automatically. Signatures match .on() (including delegation since 1.7).
.on() keeps the handler until you .off() it. .one() removes it after the first invocation on that element for that event type.
Yes for a single event type. $("#foo").one("click", fn) is equivalent to binding with .on("click", …) and calling $(this).off(event) inside after the first run.
With .one("click mouseenter", fn), the handler can run once for click and once for mouseenter on the same element — once per type, not once total.
Yes since 1.7: .one(events, selector, handler). The once-limit applies to the element you called .one() on (the root). After the first matching descendant event, that delegated binding is spent for that event type.
First-click tutorials, one-time confirms, lazy init on first interaction, or any handler you would remove immediately after it runs. Use .on() when it must keep firing.

Next: .trigger()

Fire native or custom events — including one-shot handlers.

.trigger() tutorial →

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