Skip to content

Instantly share code, notes, and snippets.

View fabrizim's full-sized avatar

fabrizim

View GitHub Profile
@fabrizim
fabrizim / jquery.prebind.js
Created October 17, 2015 01:29 — forked from jonathanconway/jquery.prebind.js
preBind() - Add an event binding *before* any pre-existing bindings. (An early version, may not work in all scenarios)
$.fn.preBind = function(type, data, fn) {
var currentBindings = this.data('events')[type];
var currentBindingsLastIndex = currentBindings.length - 1;
var newBindings = [];
// bind the event
this.bind(type, data, fn);
// move the new event to the top of the array
newBindings.push(currentBindings[currentBindingsLastIndex]);