Skip to content

Instantly share code, notes, and snippets.

View stpettersens's full-sized avatar

Sam Saint-Pettersen stpettersens

View GitHub Profile
@jonathanconway
jonathanconway / jquery.prebind.js
Created June 25, 2011 05:53
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]);