JSFiddle - React, Tailwind, and code Playground

by sandro_paganotti

HTML

<button>Segnala</button>

JavaScript

var button = document.querySelector('button');

button.addEventListener('click', function(){
    var evt = document.createEvent('CustomEvent');
    evt.initCustomEvent('sayhello', true, true, {msg: "hello!"});
    document.dispatchEvent(evt);
});

document.addEventListener('sayhello', function(evt){
    console.log(evt);
});