Skip to content

Instantly share code, notes, and snippets.

@rwz
Created July 14, 2010 13:43
Show Gist options
  • Save rwz/475419 to your computer and use it in GitHub Desktop.
Save rwz/475419 to your computer and use it in GitHub Desktop.
/*
Prototype's helper for quick and easy observing
click events on different elements including
anchors with '#' href
Usage examples:
instead of:
elementsArray.invoke('observe', 'click', function(event){
var el = event.findElement();
event.preventDefault();
doStuffWithElement(el)
});
do this:
elementsArray.invoke('clk', doStuffWithElement);
*/
(function(){
'use strict';
Element.clk = function(element, callback){
element.observe('click', function(event){
event.stop();
callback(element, event);
});
};
Element.prototype.clk = Element.clk.methodize();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment