Looking for a best practice here. But I just recently upgraded an app from jQuery 1.4 to 1.8 and I’m slowly switching out all the live calls to on calls.
$(document).on('click', 'a.edit', function(){
from :
$("a.edit").live(function() {
-
Would it be faster to bind it to something more specific other than document?
-
Is there a speed difference between these two calls as is?
Delegating events to the document now means that all elements inside the document when clicked will fire the event handler, and then it checks to see if the target matches
a.edit, and that’s a lot of checking. Narrowing it down to an element closer toa.editwill mean less elements fire the event handler, and fewer elements to check for a match with the specified target.From the jQuery docs :
What it basically does is something like: