Skip to content

Instantly share code, notes, and snippets.

@cowboy
Created July 30, 2010 14:59
Show Gist options
  • Save cowboy/500667 to your computer and use it in GitHub Desktop.
Save cowboy/500667 to your computer and use it in GitHub Desktop.
jQuery liveOne: The power of .live and .one, together at last! (NOT FULLY TESTED) see http://jsfiddle.net/cowboy/gjcSE/
/*!
* jQuery liveOne - v0.1 - 07/30/2010
* http://benalman.com/
*
* Copyright (c) 2010 "Cowboy" Ben Alman
* Dual licensed under the MIT and GPL licenses.
* http://benalman.com/about/license/
*/
// The power of .live and .one, together at last!
(function($,undefined){
'$:nomunge'; // Used by YUI compressor.
$.fn.liveOne = function( types, data, fn ) {
var that = this;
if ( $.isFunction( data ) ) {
fn = data;
data = undefined;
}
function wrapper() {
that.die( types, wrapper );
return fn.apply( this, arguments );
};
if ($.guid) {
wrapper.guid = fn.guid = fn.guid || $.guid++;
}
return that.live( types, data, wrapper );
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment