Trigger Events
Lesson 14Author : GOUP
Last Updated : September, 2020
Code
Inline Event Listeners
index.htmlCopy<h1 id="myHeader" onclick="handleClick(this)">GOUP</h1> <script src="script.js"></script>
script.jsCopyfunction handleClick(element){ alert("Clicked " + element.id); }
Programatic Event Listeners
index.htmlCopy<h1 id="myHeader">GOUP</h1> <script src="script.js"></script>
script.jsCopyvar header = document.getElementById("myHeader"); header.addEventListener("click", function(){ alert("You clicked " + header.id); });