From the course: JavaScript: Events
Unlock the full course today
Join today to access over 22,400 courses taught by industry experts or purchase this course individually.
Preventing default events - JavaScript Tutorial
From the course: JavaScript: Events
Preventing default events
So far we looked at different mass related events and learn how to add and delete DOM elements. Plus we also learned how to remove event listeners when necessary. I want to show you an example of how can you prevent some of the fault actions when working with events. So I'm going to use an event then handles right clicks called Context Menu. So let's go ahead and go into our code, and just update this paragraph, because we're going to do something a little bit different. So, I'm going to say right click on the image to see a larger version. And also announce that the preview is going to follow the mouse. So I'll be using another event called mouse move to track the position of the mouse, you can get an idea of how that works. So that's all we need for the HTML and we'll dig into the JavaScript next. So, first thing I need to do is change my event so that instead of detecting a mouse over. It's going to detect something called context menu. So, now, if we go back into our movie, we…
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.