Trigger Events

Lesson 14
Author : Afrixi
Last Updated : October, 2017


Javascript - Program the Web
This course covers the basics of programming in Javascript. Work your way through the videos/articles and I'll teach you everything you need to know to make your website more responsive!

Code

Inline Event Listeners

index.htmlCopy
<h1 id="myHeader" onclick="handleClick(this)">Afrixi</h1> <script src="script.js"></script>
script.jsCopy
function handleClick(element){ alert("Clicked " + element.id); }

Programatic Event Listeners

index.htmlCopy
<h1 id="myHeader">Afrixi</h1> <script src="script.js"></script>
script.jsCopy
var header = document.getElementById("myHeader"); header.addEventListener("click", function(){ alert("You clicked " + header.id); });