The one() method is an inbuilt method in jQuery that attaches one or more event handlers for the selected element. This also attaches a function to run when the event occurs. This method named one because whatever event handler attaches to this method will run only once.
$(selector).one(event, data, function)
Parameter: This method accepts three parameter as mentioned above and described below:
- event: It is required parameter. It is used to specify one or more events to attach to the elements. If multiple events given then use space to separate them.
- data: It is optional parameter. It is used to specify additional data to pass along to the function.
- function: It is required parameter. It is used to specify the function to run when the event occurs.
Return Value: This method returns the selected element with the specified event handler.