JSFiddle - React, Tailwind, and code Playground
HTML
<p>Has an attached custom event.</p>
<div class="box">
<span style="display:none;"></span>
</div>
CSS
p {
color: red;
}
span {
color: blue;
}
button{ clear:both; display:block}
.btn{
cursor:pointer;
}
JavaScript
$( "p" ).on( "myCustomEvent", function( event, myName ) {
$( this ).text( myName + ", hi there!" );
$( "span" )
.stop()
.css( "opacity", 1 )
.text( "myName = " + myName )
.fadeIn( 30 )
.fadeOut( 5000 );
});
$( document ).on('click',".btn",function () {
$( "p" ).trigger( "myCustomEvent", [ "John" ] );
// alert(1);
});
var loop = setInterval(function(){
$('.box').append('<div class="btn">Trigger custom event</div>');
},1000);
window.setTimeout(function(){ clearInterval(loop); },2000);