How to bind events in jQuery for an element created after loading a document?

I have a set of list items in unordered lists into which I anchor the anchor inside them to shoot when clicked. The fact is that some ul are created (via ajax) when I click on some of the created, in the first place, li related in jQuery document.ready. And I want this lithium to be created dynamically for firing. Can I do it?

Ok, hope you understand what I mean ...

+3
source share
3 answers

Check out the live () method

Use it just like bind (), i.e.:

$('.class').live('click', function() { 
     alert('bla');
   }
);
+13
source
+2

live() ul, live. :

$('ul').live('click', function() {
  // your code here...
}

live .

+2

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


All Articles