Locked lesson.
About this lesson
What are event listeners, and how to listen for event handlers.
Exercise files
Download this lesson’s related exercise files.
EventListeners.docx59.2 KB EventListeners - Solution.docx
59.2 KB
Quick reference
Event Listeners
Event listeners are very, very similar to events.
When to use
Events and event listeners are used interchangeably.
Instructions
To add an event listener:
<p id="first">This is my p tag!</p>
<script>
document.getElementById("first").addEventListener("click", myFunction);
function myFunction(){ alert("I'm Popping Up!");}
</script>
That creates a popup box whenever someone clicks the p tag.
Hints & tips
- Events and event listeners are basically the same thing
Lesson notes are only available for subscribers.