.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);
});
Call
What 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
Parameter
Description
events [
Used in .one(events [, data], handler). Direct one-shot bind
data]
Used in .one(events [, data], handler). Direct one-shot bind
handler
Used 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 Value
Description
jQuery object
Most 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.");
});
First click → message updates
Second click → no change from this handler
How It Works
Bind..one("click", …) attaches a temporary handler.
First. The click runs your function.
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)
);
});
mouseenter → 1 · mouseenter
click → 2 · click
further same types → ignored
How It Works
Two types. Space-separated names create two one-shot slots.
Enter. First mouseenter runs and clears that type.
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.