From the course: JavaScript Essential Training

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Advanced event listeners and "this"

Advanced event listeners and "this" - JavaScript Tutorial

From the course: JavaScript Essential Training

Start my 1-month free trial

Advanced event listeners and "this"

- [Instructor] Now that our event listener is working, we need to expand its functionality a bit. For one thing, the button text needs to be updated to reflect what the button actually does. Right now, it says open lid when the lid is closed. And when I click on it, it also says open lid when the lid is open. So it should really say close lid when the lid is open and vice versa. Secondly, we need to update the property for lid status in the object itself. So if that object was living in a database, and we want to pass that object back into the database to change the status, we can do that. This serves as a good example to highlight an important issue when choosing whether to use an arrow function or a function declaration as the event listener callback. Let me show you what I mean. In our event listener here, we are targeting the button element and then adding an event listener to it. So if I want to change the text…

Contents