Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery 1.9.0 live function?

Tags:

jquery

There is no live() function in jquery 1.9.0, but jquery.unobtrusive.ajax.js is already use this function.

Should I use older version of jquery or another way?

like image 344
AliRıza Adıyahşi Avatar asked Jan 29 '13 23:01

AliRıza Adıyahşi


People also ask

What is Live function in jQuery?

jQuery live() Method The live() method attaches one or more event handlers for selected elements, and specifies a function to run when the events occur. Event handlers attached using the live() method will work for both current and FUTURE elements matching the selector (like a new element created by a script).


2 Answers

Depreciated as of 1.7 and removed as of 1.9. Use on() instead.

http://api.jquery.com/on/

$("#myButton").on("click", function(){
    alert("Clicked");
});

Lots of good info here:

http://www.elijahmanor.com/2012/02/differences-between-jquery-bind-vs-live.html

As for Unobtrusive Ajax, you will need to include a version of jQuery prior to v1.9 where live() still exists.

If you are referencing the MS CDN,

http://ajax.aspnetcdn.com/ajax/mvc/3.0/jquery.unobtrusive-ajax.js http://ajax.aspnetcdn.com/ajax/mvc/3.0/jquery.unobtrusive-ajax.min.js

then it does not appear that these directly reference jQuery. Simply include the 1.8 version in your code instead of the 1.9 version.

like image 135
andleer Avatar answered Oct 30 '22 12:10

andleer


.live() has been replaced with the event delegation syntax of .on():

$('#parent').on('click', '.child', function() {
  ...
});

#parent should exist when you call your selector, so if your element is top-level, use document as the parent.

like image 20
Blender Avatar answered Oct 30 '22 11:10

Blender