I have made on click function for dynamic elements but its not working, Is there a way around it?
$( "p" ).on( "myCustomEvent", function( event, myName ) {
$( this ).text( myName + ", hi there!" );
$( "span" )
.stop()
.css( "opacity", 1 )
.text( "myName = " + myName )
.fadeIn( 30 )
.fadeOut( 5000 );
});
$( "button" ).click(function () {
$( "p" ).trigger( "myCustomEvent", [ "John" ] );
//alert(1);
});
var loop = setInterval(function(){
$('.box').append('<button>Trigger custom event</button>');
},1000);
window.setTimeout(function(){ clearInterval(loop); },2000);
For code click here