Home

defaultPrevented

defaultPrevented is a boolean property of the Event interface in web browsers. It indicates whether preventDefault() has been called on a given event. When true, the event’s default action should be prevented; when false, the default action may proceed.

Whether defaultPrevented can be set depends on the event’s cancelable flag. If an event.cancelable is true,

During event dispatch, the default action associated with a cancelable event will be suppressed when defaultPrevented

Usage commonly involves calling preventDefault() within an event handler to stop a default action, such as preventing

See also: Event.preventDefault(), Event.cancelable, Event.

calling
preventDefault()
on
that
event
sets
defaultPrevented
to
true.
If
the
event
is
not
cancelable,
calling
preventDefault()
has
no
effect
and
defaultPrevented
remains
false.
The
value
is
useful
for
coordinating
between
multiple
event
handlers
and
the
user
agent’s
own
default
actions.
is
true.
Examples
include
following
a
link,
submitting
a
form,
or
triggering
a
browser’s
default
behavior
for
certain
key
presses.
In
handlers,
code
may
check
event.defaultPrevented
to
determine
whether
a
previous
handler
or
the
user
agent
prevented
the
default
action,
and
adapt
behavior
accordingly.
a
form
from
submitting
so
that
custom
validation
can
run
first.
Later
logic
can
inspect
event.defaultPrevented
to
decide
how
to
proceed.
Some
older
environments
used
alternative
mechanisms,
such
as
setting
returnValue
to
false,
to
achieve
a
similar
effect.