I'm practically using this code, if you click the X button it closes, it hides: https://jsfiddle.net/pkLj6fst/5/
The only difference is that apart from the .loads of my code is that I am getting response from PHP in json format:
$(function() {
    $(document).on('click', '.close', function(event){
        event.preventDefault();
        $('.alert-success').fadeOut(500);
    });
/*$('.alert-success').on('click', 'button', function(event){
    event.preventDefault();
    $('.alert-success').fadeOut(500);
});*/
    $(document).on('click', '.addCard', function(e){
        e.preventDefault();
        var itemId = $(this).attr("id");
        $.ajax({
            url:"add_item.php",
            method:"POST",
            data:{itemId:itemId},
        })
        .done(function(data){
            let res = JSON.parse(data);
            if(res.status){
                $("#wrapp-basket").load(" #wrapp-basket").fadeIn();
                $("#addCard").load(" #addCard").fadeIn();
                $("#qty").load(" #qty").fadeIn();
                $('.alert-success').fadeIn();
                $('.alert-success').html(res.message).delay(8000).fadeOut(8000);
                $(".alert-success").append("<button class='close' type='button'><span aria-hidden='true'>×</span></button>");
            } else {
                $('.alert-danger').fadeIn();
                $('.alert-danger').html(res.message).delay(8000).fadeOut(8000);
            }
            console.log(data);
        })
        .fail(function( jqXHR, textStatus ) {
            alert("Ajax Request fail");
        })
    });
});
In conclusion in created element: $(".alert-success").append("<button class='close' type='button'><span aria-hidden='true'>×</span></button>"); it does not work, that is, when I click the X button it does not close, it does not hide.
I have reviewed the following sources: https://learn.jquery.com/events/event-delegation/
But nothing, I have tried in various ways and, I can not hide it, please can you help me, explain how to solve this problem, thank you.
