Kayla Budzeak
2 min readApr 30, 2021

JavaScript Events

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.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Kayla Budzeak
Kayla Budzeak

Written by Kayla Budzeak

I'm a Full-Stack Software Engineer, with a background in customer service, who recently graduated from Flatiron School. In my down time I love to bake & garden.

No responses yet

Write a response