The defaultPrevented event property in HTML is used to check whether the preventDefault() method was called or not. It returns a boolean value i.e. true if the preventDefault() method was called, else false.
Following is the syntax −
event.defaultPrevented
Let us now see an example to implement the defaultPrevented event property in HTML −
Example
<!DOCTYPE html> <html> <body> <h2>Demo Heading</h2> <a id="myid" href="https://example.com/">Demo (click me)</a> <script> document.getElementById("myid").addEventListener("click", function(event){ event.preventDefault() alert("Was preventDefault() called: " + event.defaultPrevented); }); </script> </body> </html>
Output
Click on the link and the following would get displayed in the alert box −