custom events
<h1 id="h1">Hello for John!</h1>
<script>
// catch on h1
h1.addEventListener("hello", function(e) {
console.log(e.detail.name);
});
// ⭐️ custom event
let event = new CustomEvent("hello", {
detail: { name: "John" } // ⭐️ custom info in `detail` property
});
// dispatch on h1
h1.dispatchEvent(event);
</script>Last updated