event.defaultPrevented

  • Revision slug: DOM/event.defaultPrevented
  • Revision title: event.defaultPrevented
  • Revision id: 13880
  • Created:
  • Creator: airportyh
  • Is current revision? No
  • Comment 12 words added, 6 words removed

Revision Content

{{ DomRef() }}

Summary

Returns a boolean indicating whether or not {{ domxref("event.preventDefault()") }} was called on the event.

Note: You should use this instead of the non-standard, deprecated getPreventDefault() method (see {{ bug("691151") }}).

Syntax

bool = event.defaultPrevented 

Example

 if (e.defaultPrevented) {
   /* the default was prevented */
 }

Browser compatibility

{{ CompatibilityTable() }}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support {{ CompatChrome("18") }} {{ CompatGeckoDesktop("6.0") }} {{ CompatInternetExplore("9") }} {{ CompatOpera("11") }} {{ CompatSafari("5.0") }}
Feature Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support {{ CompatUnknown() }} {{ CompatGeckoMobile("6.0") }} {{ CompatUnknown() }} {{ CompatUnknown() }} {{ CompatUnknown() }}

Specification

{{ languages( {"zh-cn": "zh-cn/DOM/event.defaultPrevented" } ) }}

Revision Source

<p>{{ DomRef() }}</p>
<h3>Summary</h3>
<p>Returns a boolean indicating whether or not {{ domxref("event.preventDefault()") }} was called on the event.</p>
<div class="note"><strong>Note:</strong> You should use this instead of the non-standard, deprecated<code> getPreventDefault()</code> method (see {{ bug("691151") }}).</div>
<h3>Syntax</h3>
<pre class="eval">bool = event.defaultPrevented </pre>
<h3>Example</h3>
<pre> if (e.defaultPrevented) {
   /* the default was prevented */
 }
</pre>
<h3>Browser compatibility</h3>
<p>{{ CompatibilityTable() }}</p>
<div id="compat-desktop"> <table class="compat-table"> <tbody> <tr> <th>Feature</th> <th>Chrome</th> <th>Firefox (Gecko)</th> <th>Internet Explorer</th> <th>Opera</th> <th>Safari</th> </tr> <tr> <td>Basic support</td> <td>{{ CompatChrome("18") }}</td> <td>{{ CompatGeckoDesktop("6.0") }}</td> <td>{{ CompatInternetExplore("9") }}</td> <td>{{ CompatOpera("11") }}</td> <td>{{ CompatSafari("5.0") }}</td> </tr> </tbody> </table>
</div>
<div id="compat-mobile"> <table class="compat-table"> <tbody> <tr> <th>Feature</th> <th>Android</th> <th>Firefox Mobile (Gecko)</th> <th>IE Mobile</th> <th>Opera Mobile</th> <th>Safari Mobile</th> </tr> <tr> <td>Basic support</td> <td>{{ CompatUnknown() }}</td> <td>{{ CompatGeckoMobile("6.0") }}</td> <td>{{ CompatUnknown() }}</td> <td>{{ CompatUnknown() }}</td> <td>{{ CompatUnknown() }}</td> </tr> </tbody> </table>
</div>
<h3>Specification</h3>
<ul> <li><a class="external" href="http://www.w3.org/TR/2006/WD-DOM-Level-3-Events-20060413/events.html#Events-Event-defaultPrevented" title="http://www.w3.org/TR/2006/WD-DOM-Level-3-Events-20060413/events.html#Events-Event-defaultPrevented">DOM 3 Events</a></li>
</ul>
<p>{{ languages( {"zh-cn": "zh-cn/DOM/event.defaultPrevented" } ) }}</p>
Revert to this revision