Open In App

HTML DOM cancelable Event Property

Last Updated : 30 Sep, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

The cancelable event property indicates whether the event's default action can be prevented. If the value is true, the default action can be prevented using event.preventDefault(). If false, the default action cannot be prevented. It is a read-only property.

It is a read-only boolean property.

Syntax:

event.cancelable

Return Value:

It returns a Boolean which indicates whether the event is cancelable or not.

  • It returns true indicating the event is cancelable.
  • It returns false indicating the event is not cancelable.

Example:

html
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" 
          content="width=device-width, initial-scale=1.0">
    <title>DOM cancelable Event Property</title>
</head>

<body style="text-align:center">

    <h1 style="color: green;">GeeksforGeeks</h1>
    <h2>DOM cancelable Event Property</h2>

    <button onclick="Geeks(event)">Click Here!</button>

    <p id="p"></p>

    <script>
        function Geeks(event) {
            // Check if the event is cancelable
            let isCancelable = event.cancelable;

            // Display the result in the paragraph
            document.getElementById("p").innerHTML 
             = "Cancelable: " + isCancelable;
    </script>

</body>

</html>

Output:


Supported Browsers:

The browser supported by cancelable Event property are listed below:

  • Apple Safari
  • Google Chrome
  • Firefox
  • Opera

Next Article

Similar Reads