Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Like jQuery's .one but runs only once, across multiple elements and/or event types.
/*!
* jQuery oneOnly - v0.1pre - 03/30/2011
* http://benalman.com/
*
* Copyright (c) 2011 "Cowboy" Ben Alman
* Dual licensed under the MIT and GPL licenses.
* http://benalman.com/about/license/
*/
(function($){
$.fn.oneOnly = function( types ) {
var elems = this,
args = Array.prototype.slice.call(arguments),
fn = args.pop();
function handler() {
elems.unbind(types, handler);
return fn.apply(this, arguments);
}
return this.bind.apply(this, args.concat(handler));
};
})(jQuery);
@cowboy

This comment has been minimized.

Copy link
Owner Author

cowboy commented Mar 30, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.