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

Preventing default events - JavaScript Tutorial

From the course: JavaScript: Events

Start my 1-month free trial

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…

Contents