jQuery .one() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Event Handler

Definition

.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).

Syntax

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

jQuery
$("#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);
});
CallWhat it does
.one(events [, data], handler)Direct one-shot bind
.one(events [, selector] [, data], handler)Delegated one-shot bind
.one(eventsMap [, selector] [, data])Object map of event → handler

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

Parameters

ParameterDescription
events [Used in .one(events [, data], handler). Direct one-shot bind
data]Used in .one(events [, data], handler). Direct one-shot bind
handlerUsed in .one(events [, data], handler). Direct one-shot bind
selector] [Used in .one(events [, selector] [, data], handler). Delegated one-shot bind
eventsMap [Used in .one(eventsMap [, selector] [, data]). Object map of event → handler

Return Value

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

jQuery Examples

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.

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.

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.

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() Method

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

.trigger() Method 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