I wanna trigger click on button. But the problem is the click event will always triggered before the button is loaded
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
$(document).ready(function(){
$('.custom_button').click(function(){
alert('show');
});
$('.custom_button').click();
$('body').append('<button class="custom_button">abc</button>');
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
How to do this so the $('.custom_button').click();
will be trigger whenever the button is loaded into page?