.live()
is dead, long live .live()
:
https://github.com/jquery/jquery/commit/eed78cc321ed7e2b37fb34e32fbb528b24f61d6e
Though seriously, for the one-liner you seek, you can just add it back:
jQuery.fn.live = function( types, data, fn ) { jQuery( this.context ).on( types, this.selector, data, fn ); return this; }
Add that towards the top of your JS to effectively create a shim that will allow you to use .live()
as you want and not care about which version of jQuery you're using.
But really, like others are saying, you should just do a find-replaceall using the text editor of your choice, or a command line utility like sed. In the shim solution I give you, you're calling a function to call another function, which introduces a lot of overhead and may use an unnecessary amount of resources. .on()
is much more efficient, especially if you call it directly.
Update: The above solution relies on jQuery's internal .context
property, which has been deprecated since jQuery 1.10 and may disappear in any subsequent version. An alternative version that should fulfill your needs most of the time would be to simply replace this.context
with document
. This has limitations outlined in the .context property's API:
The value of this property is typically equal to document, as this is
the default context for jQuery objects if none is supplied. The
context may differ if, for example, the object was created by
searching within an <iframe>
or XML document.
So it may fail. Anyway, by now you definitely have no excuse to not be using .on()
directly. Feel free to check out my tips on upgrading to the most recent version of jQuery.