JavaScript DOM Event method: preventDefault()
[this page | pdf | back links]
The preventDefault() method (when applied to
Event
objects in the JavaScript
DOM) cancels
an event if it is cancellable (i.e. it causes the default action belonging to
the event not to occur).
For example, this could
stop the browser from going to a new page when a link is clicked.
Note: Not all events are
cancellable; the event.cancelable
property will indicate whether it is cancellable. Also, the preventDefault() method does not
prevent further propagation through the DOM; to limit this, use the event.stopImmediatePropagation()
or event.stopPropagation()
methods.
It
has the following syntax with no parameters. It does not return a value.
event.preventDefault()
NAVIGATION LINKS
Contents | Prev | Next | JavaScript DOM (and BOM)