HTML defaultPrevented Event Property

HTMLWeb DevelopmentFront End Technology

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

 Live Demo

<!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 −

raja
Published on 21-Jun-2019 11:55:42
Advertisements