jquery .live('click') vs .click() -


i wondering whether there circumstances better use .click(function {...}); rather .live('click', function {...});?

from gather live option seems better option , hence using in circumstances instead of plain .click(), given lot of code loaded asynchronously.

edit: part question. if i'm asynchoronously loading javascript in, .click still pickup elements in dom. right?

there might times when explicitly want assign click handler objects exist, , handle new objects differently. more commonly, live doesn't work. doesn't work chained jquery statements such as:

$(this).children().live('click',dosomething); 

it needs selector work because of way events bubble dom tree.

edit: upvoted this, people still looking @ it. should point out live , bind both deprecated. can perform both .on(), imo clearer syntax. replace bind:

$(selector).on('click', function () {     ... }); 

and replace live:

$(document).on('click', selector, function () {     ... }); 

instead of using $(document), can use jquery object contains elements you're monitoring clicks on, corresponding element must exist when call it.


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -