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