Learn HTML DOM
Browser Events
5.8
Lesson

Preventing Default Behaviour

Sometimes, it is useful to block the default behaviour of an event.

In the example given below, we do not want the a element to redirect us to the link. Instead, we want to display the link address in a p element:

The preventDefault method blocks the event’s default behaviour. It can be used on most events. To know whether an event can be cancelled, check its event.cancelable property.