Skip to content

Event: defaultPrevented property ​

The defaultPrevented property indicates whether a listener called preventDefault() and it took effect.

Value ​

A boolean.

ValueMeaning
trueA listener called preventDefault(), and cancelable is true
falseNone did, or cancelable is false
  • Read-only. Assigning to it throws TypeError.

Examples ​

js
application.addEventListener('ask', (e) => e.preventDefault());
const event = new Event('ask', { cancelable: true });
application.dispatchEvent(event);
console.log(event.defaultPrevented);

Result: The console prints true.

See also ​