From the course: JavaScript Essential Training
Unlock this course with a free trial
Join today to access over 22,400 courses taught by industry experts.
Pass arguments through event listeners - JavaScript Tutorial
From the course: JavaScript Essential Training
Pass arguments through event listeners
- [Instructor] Working with the event listeners you'll often want to either access the event object inside the callback function or pass some argument through to the callback function. It's not immediately obvious how to do either when we are working with callback functions. So let's take a closer look. In the earliest example of an event listener, you may remember, I called in the event object as a parameter in the arrow function, and this is the answer to the first part of the question. You see, whenever you set up a new event listener and you have a callback function, the event object is automatically passed to the callback function as an argument, and we can choose to capture that object and use it in the callback function by setting up a parameter name for it. So in this case, I've set up the name event and then we use it down here. The passing of the events object happens automatically. And this is actually the…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
-
-
-
-
DOM events explained1m 41s
-
Typical DOM events5m 35s
-
Event listeners5m 45s
-
Practice: Experiment with event listeners1m 32s
-
Advanced event listeners and "this"6m 12s
-
Pass arguments through event listeners4m 53s
-
Challenge intro: Create an event listener2m 15s
-
Solution: Create an event listener6m 16s
-
-
-