Jquery click event not working on div loaded with ajax

I have a jquery script using .ajax that loads a new div containing the response information. Part of the content of this div is a link that says remove. When the click is removed, I want the parent div to hide. This does not seem to work.

$(document).ready(function(){
  $('.remove').click(function() { 
    $('.remove').parent().hide();
  });
});

This does not affect the fact that it was. This code seems to work if the div I'm trying to work with is not loading using ajax. Any ideas?

+3
source share
1 answer

Try living (added in 1.3):

$(document).ready(function(){
      $('.remove').live('click', function() {
          $('.remove').parent().hide();
      });
});

Person: http://api.jquery.com/live/

+4
source

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


All Articles