Last updated 2 years ago
Was this helpful?
⟩ ⟩ ⟩ custom events
event.isTrusted - event comes from browser (true) or script (false).
bubbling phase
<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>
JS.info ⟩
JavaScript The Definitive Guide (15.2 Events)
⟩
- event.composed