If you want to handle the click
event with a delegate, you can do so as follows:
$(document).on('click', '.ajax-close', function( event ){
//your code goes here
});
Another approach could be nesting your click
listener inside the initial click
listener that generates the "Close" button. The issue may arise if the click
event on "ajax-close" is bound too early (before the <span>
is added to the DOM):
ajaxcontent.click(function(event) {
event.preventDefault();
$( '.ajax-live' ).addClass('ajax-live-on');
$( this ).after('<span class="ajax-close animated bounceInRight">Close</span>');
$('.ajaxshow').append().load(ajaxUrl);
$('.ajaxshow').addClass('animated bounceInUp');
// This section should now be moved here, previously it was located below
$('.ajax-close').click(function( event ){
event.preventDefault();
alert('hi there');
$( '.ajax-live' ).removeClass('ajax-live-on');
});
});
Remember to include some text in your "ajax-close" span for it to be clickable, such as the word "Close".