In this section I will be covering a simple example of an event listener using the addEventListener method. This works by gaining a reference to an element by whatever means, such as with document.getElementById, and then calling the addEventListener method of that element. The first argument that I give to addEventListener is the type of event I which to attach for, and the second argument is the method that I want to fire when this event occurs.
So I have some html for this example that looks like this.
And the html links to an external main.js file that looks like this.
For the most part addEventListener should be used as a way to attach events to an element. This way if I want I can attach more than one handler for the same event and element.