Say, for example, that I have buttons that trigger AJAX requests when clicked.
$(document).ready(function(){ $('button').each( function() { $(this).click( function() { alert('Clicked.');
When I press the button, everything works fine.
But if I load the buttons with the AJAX request, and then click on them, the code above stops working.
How can I get rid of this?
I tried the on() method
$(document).ready(function(){ $('button').each( function() { $(this).on('click', function() { alert('Clicked.');
But still. It works fine, does not work with loaded AJAX content.
I'm stuck, please help me.
PS: I am using the latest version of jQuery (v1.7.1).
source share