Name
Event.preventDefault( ) — cancel default action of an event
Availability
DOM Level 2 Events
Synopsis
void preventDefault( );
Description
This method tells the web browser not to perform the default action
(if any) associated with this event. For example, if the
type
property is “submit”, any event
handler called during any phase of event propagation can prevent the
form submission by calling this method. Note that if the
cancelable
property of an Event object is
false
, either there is no default action or there
is a default action that cannot be prevented. In either case, calling
this method has no effect.
Get JavaScript: The Definitive Guide, Fourth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.