You are here: Reference > JavaScript > client-side > event handling > methods > getPreventDefault (event)

getPreventDefault method (event)

Browser support:
Returns whether the default action of the current event is canceled or not.
The default action can be canceled with the preventDefault method and the returnValue property. When an event handler returns false, it also cancels the default action. See the example for details.


object.getPreventDefault ( );
You can find the related objects in the Supported by objects section below.

Return value:

Boolean. One of the following values:
false The default action is not canceled.
true The default action is canceled.

Example HTML code 1:

This example illustrates the use of the getPreventDefault method:
    <script type="text/javascript">
        function OnBodyClick (event) {
            if (event.getPreventDefault) {  // Firefox, Opera, Google Chrome and Safari
                if (event.getPreventDefault ()) {
                    alert ("The default action is canceled.");
                else {
                    alert ("The default action is not canceled.");

        function OnCheckBoxClick1 (event) {
            if (event.preventDefault) { // Firefox, Opera, Google Chrome and Safari
                event.preventDefault ();    // cancels the default action of the event

        function OnCheckBoxClick2 (event) {
            return false;   // cancels the default action of the event

        function OnCheckBoxClick3 (event) {
<body onclick="OnBodyClick (event)">
    Try to check the following check boxes<br /><br />
    <input type="checkbox" onclick="OnCheckBoxClick1 (event)" />First check box<br />
    <input type="checkbox" onclick="return OnCheckBoxClick2 (event)" />Second check box<br />
    <input type="checkbox" onclick="OnCheckBoxClick3 (event)" />Third check box<br />
Did you find this example helpful? yes no

Supported by objects:

Related pages:

User Contributed Comments

Post Content

Post Content