Source Code: (back to article)
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
</head>
<body>
<h1 id="elemId">Welcome to W3Docs</h1>
<script>
document.addEventListener("welcome", function(event) {
alert("Hi, " + event.target.tagName); // Hi H1
});
let event = new Event("welcome", {
bubbles: true
});
elemId.dispatchEvent(event);
</script>
</body>
</html>