How to associate some function with a non-existent element?

My problem: after loading an element through ajax, I bind some click function, but when the user loads the same element several times, the bound action will be repeated (do not replace, at least it looks like). I tried unbind, or click(function(){return false;});, but to complete the removal of the clic action from the element ...). What is the standard solution to this problem?

+3
source share
2 answers

For most events, you can use live()(jQuery 1.3 +):

$("td").live("click", function() {
  // do stuff
});

This will associate the click event with the elements <td>that appear after this code is run.

, / , , .

+6

jQuery 1.3.2, $('').live('click', function() {});, , , . .

+1

Source: https://habr.com/ru/post/1720703/


All Articles