
Have you ever wondered what happens when you click on something in your browser? Like, when you click on a picture and something pops up on the screen? This is an example of a JavaScript Event!
JavaScript gives our browser the ability to “listen” for things (events) that happen within it. These events then trigger some kind of work, such as a function, to occur when they are detected.
Some of the more common events are what are classified as mouse events, like 'click'
, 'scroll'
, 'right-click'
, or even 'mouseover'
. Other common events include keypress
events and form submissions.

In the above example, the function addClicksToLinks contains two different event listeners, although they are listening for the same type of event, they are looking for different elements.
The ‘books’ event listener will be listening for a ‘click’ on any list elements that contain a link with the class of ‘books’; the ‘authors’ listener is listening for a link with the class of ‘authors’. When a corresponding book or author is clicked it will trigger the showBook
or the showAuthor
function, respectively, to run.

As an example of a different type of event, line 128 in the above example is listening for an 'submit'
event; this occurs typically when a form is submitted. The submit event from this event listener will trigger the createBook
function to run.
This is just a small sampling of JavaScript event types; a more complete listing of events can be found here: https://developer.mozilla.org/en-US/docs/Web/Events.