.one()
methodThe .one()
method in jQuery is used to attach an event handler to the selected elements. The handler is executed at most once per element per event type.
.one()
method Syntax.one(events[,selector][,data],handler)
Parameter | Type | Description |
---|---|---|
events |
String | A string contain space-separated event types and optional namespacessuch as click ,submit ,keydown.myPlugin . |
handler |
Function | event handler function to execute when the event is triggered. It's executed at most one time per element per event type. |
selector |
String | A selector used to filter selected elements that trigger the event |
data |
Anything | Data to be passwd to the handler |
.one()
method Exampleevent type is unbound after the handler's first invocation for a given element.
$( "p" ).one( "click", function() { alert( $( this ).text() ); });