Skip to content

Instantly share code, notes, and snippets.

@attila
Forked from jonathanconway/jquery.prebind.js
Last active February 21, 2017 00:11
Show Gist options
  • Save attila/5574857 to your computer and use it in GitHub Desktop.
Save attila/5574857 to your computer and use it in GitHub Desktop.
Use $._data to get event data as $(this).data('events') has been removed from jQuery 1.8+
$.fn.preBind = function(type, data, fn) {
this.each(function() {
var $this = $(this);
$this.bind(type, data, fn);
var currentBindings = $._data($this[0], 'events');
if ($.isArray(currentBindings[type])) {
currentBindings[type].unshift(currentBindings[type].pop());
}
});
return this;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment