Mark DiMarco

UI Developer at Bazaarvoice

jQuery .live() Gotchya

I was recently trying to fix a bug somebody introduced in our app, and after a bunch of digging I found the misunderstanding of $.fn.live.

tldr: cacheing a selector, then attaching a $.fn.live event listener, then attempting to use that cached selector (accessed via closure) can break.

The cached selector is not live, but attaching the event handler via $.fn.live works.

For this to work as expected, you’d have to do a re-selection within the event handler, instead of trying to use a cached selector.

Good thing that $.fn.live is deprecated as of jQuery 1.7