defaultPrevented Event Property

Example

Prevent a link from opening the URL, and check if preventDefault() was called:

document.getElementById("myAnchor").addEventListener("click", function(event){
  event.preventDefault()
  alert("Was preventDefault() called: " + event.defaultPrevented);
});
Try it Yourself »

Description

The defaultPrevented event property checks whether the preventDefault() method was called for the event.


Syntax

event.defaultPrevented

Technical Details

Return Value: A Boolean, indicating whether the preventDefault() method was called for the event.

Possible values:

  • true - The preventDefault() method was called for the event
  • false - The preventDefault() method was not called for the event
DOM Version: DOM Level 3 Events

Browser Support

event.delfaultPrevented() is a DOM Level 3 (2004) feature.

It is fully supported in all modern browsers:

Chrome Edge Firefox Safari Opera IE
Yes Yes Yes Yes Yes 11


Copyright 1999-2023 by Refsnes Data. All Rights Reserved.