Skip to content

Instantly share code, notes, and snippets.

@KrofDrakula
Forked from remy/jquery.live.js
Created June 17, 2010 10:23
Show Gist options
  • Save KrofDrakula/441942 to your computer and use it in GitHub Desktop.
Save KrofDrakula/441942 to your computer and use it in GitHub Desktop.
// is there any reason why I can't use this pattern to replace .live
// in favour for .delegate?
(function ($) {
$.root = $(document); // hat tip: Cory Hart
// keep safe
$.fn._live = $.fn.live;
$.fn._die = $.fn.die;
$.fn.extend({
live: function (type, fn) {
$.root.delegate(this.selector, type, fn);
return this;
},
die: function (type, fn) {
$.root.undelegate(this.selector, type, fn);
return this;
}
});
})(jQuery);
@KrofDrakula
Copy link
Author

Rewritten to use the extend() method. Not really necessary, but a guideline when writing plugins. Not sure about overwriting, though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment