JavaScript in Plain English

New JavaScript and Web Development content every day. Follow to join our 3.5M+ monthly readers.

Follow publication

Member-only story

JavaScript Events Handlers— , , and

John Au-Yeung
JavaScript in Plain English
6 min readJan 24, 2020

Photo by Abigail Keenan on Unsplash

In JavaScript, events are actions that happen in an app. They’re triggered by various things like inputs being entered, forms being submitted, and changes in an element like resizing, or errors that happen when an app is running, etc. We can assign event handler to handle these events. Events that happen to DOM elements can be handled by assigning an event handler to properties of the DOM object for the corresponding events. In this article, we will look at the , , and event handlers.

onfocus

The property of the object lets us set an event handler for the event, which is the opposite of the event. The event is trigger when a user sets focus on an HTML element. If we want to the focus event to fire for non-input elements, we have to put attribute to it. What that attribute added we can focus on it with our computer’s Tab key. For example, we can attach the event handler to the object by writing:

document.onfocus = () => {
console.log('focus');
}

We can also get the object that triggered the focus event by adding the parameter to the event handler function like in the following code:

document.onfocus = (event) => {
console.log(event);
}

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Published in JavaScript in Plain English

New JavaScript and Web Development content every day. Follow to join our 3.5M+ monthly readers.

No responses yet

Write a response