Skip to content

Instantly share code, notes, and snippets.

@davidhellsing
Created May 29, 2013 11:24
Show Gist options
  • Save davidhellsing/5669606 to your computer and use it in GitHub Desktop.
Save davidhellsing/5669606 to your computer and use it in GitHub Desktop.
Detect possibly conflicting or multi-bound events in jQuery
(function($) {
var add = $.event.add;
$.event.add = function() {
var elem = arguments[0],
types = arguments[1];
if ( !types || !elem ) return add.apply(this, arguments);
types = (types || "").match(/\S+/g) || [];
var events = $._data(elem).events;
if ( events && types.length ) {
$.each(types, function(i, type) {
if ( type in events ) console.warn('Multiple event type "'+type+'" detected.', elem, events[type]);
});
}
return add.apply(this, arguments);
};
}(jQuery));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment