Skip to content

Instantly share code, notes, and snippets.

@infostreams
Last active April 5, 2017 07:49
Show Gist options
  • Save infostreams/6540654 to your computer and use it in GitHub Desktop.
Save infostreams/6540654 to your computer and use it in GitHub Desktop.
ensures a handler is run before any other registered handlers, independent of the order in which they were bound. Requires jQuery > 1.7
$.fn.bindFirst = function(which, handler) {
// ensures a handler is run before any other registered handlers,
// independent of the order in which they were bound
var $el = $(this);
$el.unbind(which, handler);
$el.bind(which, handler);
var events = $._data($el[0]).events;
var registered = events[which];
registered.unshift(registered.pop());
events[which] = registered;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment