jQuery .one()
Learn all about the jQuery function .one().
The .one()
method is identical to .on()
, except that the handler is unbound after its first invocation. For example:
1
2
3
|
|
After the code is executed, a click on the element with ID foo
will display the alert. Subsequent clicks will do nothing. This code is equivalent to:
1
2
3
4
|
|
In other words, explicitly calling .off()
from within a regularly-bound handler has exactly the same effect.
If the first argument contains more than one space-separated event types, the event handler is called once for each event type.