← Back to Index

.one()

Attach a handler to an event for the elements. The handler is executed at most once per element per event type.

Examples

1. Execute once

$('button').one('click', function() {
     console.log('Prize claimed!');
});

Result

// 1st Click: Logs "Prize claimed!"
// 2nd Click: Nothing happens (listener removed).

Parameters

Parameter Type Description
eventType string One or more space-separated event types (e.g., 'click').
selector string Optional. A selector string for delegated events.
handler function A function to execute when the event is triggered.

Returns: The original SR object for chaining.