JSFiddle - React, Tailwind, and code Playground
JavaScript
window.ontest = function () {
document.body.appendChild(document.createTextNode(arguments[0].detail));
};
addEventListener('test', function (e) {
if (e.target["on" + e.type]) {
if (Array.isArray(e.target["on" + e.type])) return e.target["on" + e.type].forEach(function (f) {
f(e);
});
e.target["on" + e.type](e);
}
});
dispatchEvent(new CustomEvent("test", {
detail: {data:'data'}
}))