jQuery’s .live(), Enhanced

If you’re not using jQuery’s .live() method you are really missing out. live() works by storing a selector-to-handler mapping in an internal hash which allows it to execute the handler for all existing and future elements which match that selector. This is a fantastic feature, however the current implementation relies on real DOM elements (even if they’re not appended to the document) for access to the selector which slows it down when it really doesn’t need to.

Wouldn’t it be great if it could just store the reference (the “selector”), which would make assigning handlers a constant complexity operation? Its certainly possible, and thanks to Dave Furfero (of blurf.furf.com) you don’t have to wait for a future release of jQuery to use this. (Lets hope they include it.)

Read all about it here:http://blurf.furf.com/2009/09/jquery-live-from-new-york/

Here’s the code:

	live: function(selector, type, fn){
		var jQElem = $(document);
		jQElem.selector = selector;
		jQElem.live(type, fn);

Thanks Furf.