DOM Event.preventDefault() Method
The preventDefault() method stops the browser's default action for an event, such as following a link or submitting a form.
Description
The preventDefault() method tells the browser not to perform the event's default action: following a link, submitting a form, ticking a checkbox, typing a character, opening the context menu and so on. The event still propagates normally; use stopPropagation() to stop that. It only works on cancelable events, which defaultPrevented reports afterwards.
It has no effect in listeners added with { passive: true }.
Some default actions can't be prevented, such as closing the browser tab; the beforeunload event can only show a generic confirmation. Calling preventDefault() on keydown stops typing and browser shortcuts, so only do it for the specific keys you handle.
Syntax
event.preventDefault()Return Value
None (undefined).
Example
Browser Support
The following information will show you the current browser support for the Event.preventDefault() method. Hover over a browser icon to see the version that first introduced support for this method.
Desktop





Tablets & Mobile





