You are here: Reference > JavaScript > client-side > event handling > methods > getPreventDefault (event)
getPreventDefault method (event)
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.
Syntax:
You can find the related objects in the Supported by objects section below.
Return value:
Boolean. One of the following values:
The default action is not canceled. | |
The default action is canceled. |
Example HTML code 1:
This example illustrates the use of the getPreventDefault method:
|
||||
<head> <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) { } </script> </head> <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 /> </body> |
||||
|
||||
Did you find this example helpful?
|
Supported by objects:
Related pages:
User Contributed Comments