An event is an occurrence which when triggered, an action is supposed to be taken.
Examples of events include;
The click of a button.
A change in the input field.
A webpage finishes loading.
A form is submitted.
An event listener listens out for the event happening and the event handler is the code that runs in response to it happening. Each event has an event handler(a block of code) which runs when an event fires.
When a mouse clicks on the heading, change the font color to blue.
<!--HTML--> h1 id=”header1”>Welcome to my blog!</h1>
In the example above, we use getElementById to 'grab' the element with the id(header1).
.addEventListener() is a method.
"click" is the name of the event that we are listening for.
Upon clicking the element, the event is triggered which executes the line of code.