jQuery event.isDefaultPrevented()

Beginner
5 min read
Updated: Nov 2026
3 examples
Events

Definition

event.isDefaultPrevented() returns a Boolean: true if event.preventDefault() was called on this event, otherwise false. Added in jQuery 1.3. Takes no arguments.

Syntax

Start with these common calls. Keep them short and readable.

jQuery
event.isDefaultPrevented()  // Boolean — no arguments

// Official idea
$("a").on("click", function (event) {
  event.isDefaultPrevented();  // false
  event.preventDefault();
  event.isDefaultPrevented();  // true
});

// Pair with: preventDefault() to cancel
// Not the same as: isPropagationStopped() (bubbling flag)
CallWhat it does
eventjQuery event object in the handler
preventDefault()Sets the flag this method reads
isDefaultPrevented()Returns true / false
ArgumentsMethod takes no parameters

Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.

Parameters

ParameterDescription
Step 1Bind a handler with .on() and accept event.
Step 2Optionally read event.isDefaultPrevented() early (usually false).
Step 3Call event.preventDefault() when you need to cancel the default.

Return Value

Return ValueDescription
BooleanOften true or false depending on the match or state.

jQuery Examples

Example 1 — Official: False, Then True

Check the flag before and after preventDefault() on a link.

jQuery
$("a").on("click", function (event) {
  var before = event.isDefaultPrevented();
  event.preventDefault();
  var after = event.isDefaultPrevented();
  $("#out").text(
    "Before: " + before + "\\nAfter: " + after
  );
});
Try It Yourself

How It Works

  1. Click. The link handler runs.
  2. Before. Nothing cancelled yet → false.
  3. Prevent. preventDefault() blocks navigation.

Example 2 — Later Handler Checks the Flag

First handler may prevent; second handler reacts to that state.

jQuery
$("#go").on("click", function (event) {
  if ($("#block").prop("checked")) {
    event.preventDefault();
  }
});

$("#go").on("click", function (event) {
  if (event.isDefaultPrevented()) {
    $("#out").text("Blocked — default already prevented.");
  } else {
    $("#out").text("Allowed — default not prevented.");
  }
});
Try It Yourself

How It Works

  1. First handler. Conditionally calls preventDefault().
  2. Second handler. Runs later on the same click.
  3. Check. isDefaultPrevented() reflects the earlier call.

Example 3 — Guard a Form Submit

Prevent submit when empty; confirm the flag in the same handler.

jQuery
$("#form").on("submit", function (event) {
  if ($("#name").val().trim() === "") {
    event.preventDefault();
  }
  $("#out").text(
    "isDefaultPrevented: " + event.isDefaultPrevented()
  );
});
Try It Yourself

How It Works

  1. Submit. The form handler runs.
  2. Validate. Empty name → call preventDefault().
  3. Report. Log whether the default was cancelled.

Frequently Asked Questions

It returns true if event.preventDefault() was called on this event object during handler execution, and false otherwise. It takes no arguments. Available since jQuery 1.3.
When multiple handlers run on the same event and a later one needs to know whether an earlier handler already cancelled the default action — for example, skipping fallback navigation after a link was prevented.
In jQuery handlers, return false calls both preventDefault() and stopPropagation(). After return false, isDefaultPrevented() returns true. Prefer explicit event.preventDefault() for clarity.
Same idea. Native events expose a defaultPrevented boolean. jQuery provides isDefaultPrevented() as a method on its normalized event object for a consistent API.
No. isDefaultPrevented() only reports state. Once preventDefault() runs, the default action stays cancelled for that event dispatch.
isDefaultPrevented() reports whether the browser default was cancelled (link navigation, form submit). isPropagationStopped() reports whether bubbling was stopped. Different flags.

Next: event.stopImmediatePropagation() Method

Stop remaining handlers on the same element and bubbling.

event.stopImmediatePropagation() Method tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful