So I have Button_1 that when click, it will request a new button_2 using ajax. Both button has click event on my jquery(document).ready but when the button 2 added to the page, it doens't have jquery event on it. Is that possible?
Here is my code on page load:
jQuery(document).ready(function($){
$('#button_1').click(function(e){
e.preventDefault();
var id = $(this).data('id');
$.ajax({
type: 'POST',
url: 'get_button_2.php',
data: 'id='+id,
dataType: 'html'
})
.done(function(response){
$('#button-container').html('');
$('#button_1').remove(); // remove button 1
$('#button-container').html(response).show('500');
})
.fail(function(){
$('#button-container').html('Something went wrong');
});
});
$('#button_2').click(function(e){
e.preventDefault();
alert ('Thank You!');
});
});