Skip to content

Instantly share code, notes, and snippets.

@chicagoworks
Created December 24, 2010 18:48
Show Gist options
  • Save chicagoworks/754445 to your computer and use it in GitHub Desktop.
Save chicagoworks/754445 to your computer and use it in GitHub Desktop.
Override jquery.delegate() to accept an object
/**
* Override .delegate()
* if 'selector' is an object loop over the object and call .live() for each item
* otherwise it call .live() just like the original .delegate().
* Roughly similar to the way the map is implemented in .bind().
*/
$.fn.delegate = function(selector, types, data, fn) {
if (typeof selector === "object") {
for (var sel in selector) {
for (var type in selector[sel]) {
this.live(type, data, selector[sel][type], sel);
}
}
return this;
} else {
return this.live(types, data, fn, selector);
}
};
@adam-lynch
Copy link

I assume .delegate now calls .on() underneath?

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