custom events
JS ⟩ browser ⟩ events ⟩ custom events
event.isTrusted - event comes from browser (true) or script (false).
<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>JavaScript The Definitive Guide (15.2 Events)
Events that Cross Shadow DOM Boundary - event.composed
Last updated
Was this helpful?