From the course: Learning App Building with Vanilla JavaScript

Unlock the full course today

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

Work with the event object

Work with the event object - JavaScript Tutorial

From the course: Learning App Building with Vanilla JavaScript

Start my 1-month free trial

Work with the event object

- Our app also makes use of the jQuery dollar this selector in a few places to reference the element that was the target of an event. To convert this to vanilla JavaScript we can use properties of the event object. So first online 82 we have and if statement that starts by checking if the event parameter has a value. If it doesn't then we know there was no click to call this function and instead we're in the initial page load. But if the event parameter has a value, and the element that was clicked has the class value of selected. Then we know that one of the tabs was clicked in the results but the clicked tab is already the selected tab. So no further dom manipulation needs to happen. So I'll comment out line 82. And then on a new line, the if statement will start the same way. If event is not equal to undefined logical and, now instead of dollar this. I can references the event object and the target property. Which is a reference to the element that the event happened to. And then…

Contents