Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Start a free Courses trial
to watch this video
In this video, we'll use event handlers for the focus and blur events.
DOM and Event Listeners
element.addEventListener(eventType, callback);
eventType
could be a keyboard key press or a mouse eventβlike a mouse click. 'focus'
is the event when the cursor appears in a text input or text area, and when the form control loses 'focus'
, the 'blur'
event is triggered.
An event callback looks like this:
function (event) {
// Do something
}
Or...
event => {
// Do something
}
The event
object has a type
property for the type of event that triggered the callback and a target
property for the element from the event
object.
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up