jQuery event.preventDefault() Method

Beginner
6 min read
Updated: Oct 2026
5 examples
Live preview

What Is event.preventDefault()?

event.preventDefault() cancels the browser’s default action for the current event. Clicked anchors will not navigate; forms will not submit — unless you allow them. Takes no arguments, returns undefined. Available since jQuery 1.0. Check with event.isDefaultPrevented().

Remember
event.preventDefault()   // no args · returns undefined

$("a").on("click", function (event) {
  event.preventDefault();   // stay on this page
});

// Does NOT stop bubbling — use stopPropagation() for that
// return false in jQuery = preventDefault + stopPropagation
NeedUse
Cancel default actionevent.preventDefault()
Check if cancelledevent.isDefaultPrevented()
Stop bubblingevent.stopPropagation()
Both cancel + stop bubblereturn false (jQuery handlers)
Bind the handler.on("click", …)

How to Use preventDefault()

Call it early in the handler when you will handle the action yourself.

  1. Bind the event that has a default (click on links, submit on forms).
  2. In the handler, call event.preventDefault().
  3. Run your own logic (update UI, AJAX, SPA route, validation message).
  4. Optionally check later with event.isDefaultPrevented().
  5. Do not assume bubbling stopped — call stopPropagation() only if you need that too.
PieceRequired?Role
Cancelable eventYese.g. link click, form submit
event argumentYesjQuery event object
preventDefault()Yes (to cancel)Blocks the browser default
Custom logicOptionalWhat you do instead

Pseudocode

Pseudocode
element.on("click" | "submit" | …, handler)

when event fires:
    if we handle it ourselves:
        event.preventDefault()
        // default navigation / submit will NOT run
        do custom work
    // event still bubbles to parents
    // unless stopPropagation() or return false

Cheat Sheet

Keep these facts handy while cancelling defaults.

TopicDetail
Syntaxevent.preventDefault()
ArgumentsNone
Returnsundefined
SincejQuery 1.0
Official demoLink click → log “default click prevented”
Stops bubbling?No
Check laterevent.isDefaultPrevented()
vs return falsereturn false also stops propagation

Live Preview

Click the link — navigation is cancelled and a log line is added, like the official jQuery API demo.

Link
Click this link

Bound with .on("click") + event.preventDefault() — you stay on this page.

Log
Click the link above.

jQuery Examples

Short, copy-ready snippets. Open DevTools, or use Try It Yourself for a live editor.

Example 1 — Official Demo: Prevent Link Navigation

Cancel the default click and append a log line (official idea).

jQuery
$("a").on("click", function (event) {
  event.preventDefault();
  $("#out").append("default " + event.type + " prevented\n");
});
Try It Yourself

How It Works

  1. Bind. Listen for click on anchors.
  2. Cancel. preventDefault() stops navigation.
  3. Feedback. Append a short message to #out.
  4. Stay. The page does not leave for the link’s href.

Example 2 — Handle a Link Yourself

Block native navigation and run your own “route” message.

jQuery
$("#spa-link").on("click", function (event) {
  event.preventDefault();
  $("#out").text("Navigation prevented — handle route in JS");
});
Try It Yourself

How It Works

  1. Target. Bind on one SPA-style link.
  2. Cancel. Default href navigation is blocked.
  3. Replace. Your code shows status (or loads a view).
  4. Pattern. Same idea as client-side routers.

Example 3 — Prevent Form Submit

Stop a full page reload so you can “submit” with JavaScript.

jQuery
$("#myForm").on("submit", function (event) {
  event.preventDefault();
  $("#out").text(
    "Page did not reload — data: " + $(this).serialize()
  );
});
Try It Yourself

How It Works

  1. Bind submit. Form submit is the event with a default reload.
  2. Cancel. preventDefault() keeps you on the page.
  3. Read. serialize() shows what would have been posted.
  4. Next step. In real apps, send that data with AJAX.

Example 4 — Conditional Validation

Call preventDefault() only when the field is invalid.

jQuery
$("#myForm").on("submit", function (event) {
  if ($("#name").val().trim() === "") {
    event.preventDefault();
    $("#out").text("Name is required");
  } else {
    event.preventDefault(); // demo stays on page
    $("#out").text("Looks good — would submit");
  }
});
Try It Yourself

How It Works

  1. Check. Read the name field on submit.
  2. Empty. Prevent default and show an error.
  3. Filled. In production you might allow submit; here we still prevent so the demo stays put.
  4. Idea. Only cancel when validation fails.

Example 5 — preventDefault vs stopPropagation

Default is cancelled, but the parent click handler still runs.

jQuery
$("#parent").on("click", function () {
  $("#out").append("parent handler ran\n");
});

$("#child-link").on("click", function (event) {
  event.preventDefault();
  $("#out").append("default prevented, bubbling continues\n");
});
Try It Yourself

How It Works

  1. Child. Link click calls preventDefault() — no navigation.
  2. Bubble. The same click still reaches #parent.
  3. Both lines. Child and parent messages both appear.
  4. Contrast. stopPropagation() would block the parent handler.

Edge Cases & Pitfalls

Watch for these when cancelling defaults.

bubble

Does not stop bubbling

preventDefault() only cancels the default action. Use stopPropagation() if parents must not see the event.

false

return false does more

In jQuery handlers, return false = preventDefault() + stopPropagation(). Prefer explicit calls when you only need one.

cancel

Some events are not cancelable

Calling preventDefault() on a non-cancelable event has no effect. Stick to links, forms, and other cancelable types.

undo

Cannot undo once called

After preventDefault(), the default stays cancelled for that dispatch. Inspect with isDefaultPrevented().

Browser Support

event.preventDefault() has been available since jQuery 1.0. Cancelling default actions is a standard browser capability. Works wherever your loaded jQuery version runs.

✓ Stable · jQuery 1.0+

event.preventDefault()

Supported wherever jQuery 1.0+ is loaded. Prefer jQuery 3.x with .on() for modern event code.

100% jQuery support
Google Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Internet Explorer IE 6+ · Legacy environments
Full support
Opera All modern versions
Full support
preventDefault() 1.0+

Bottom line: Safe for production. Use it to replace native link/form behavior; pair with isDefaultPrevented() and stopPropagation() when needed.

Performance Notes

ApproachCostBest for
event.preventDefault()NegligibleAny cancelable event
Prevent on every clickFineSPA links / custom UI
Heavy work after preventCan lagKeep post-cancel work lean
return false alwaysFineOnly when you also want to stop bubble

Calling preventDefault() is cheap. Cost comes from the custom logic you run afterward — keep that focused.

Key Takeaways

  • Role: cancel the browser’s default action for this event.
  • Common uses: links that should not navigate; forms that should not reload.
  • Not bubbling: use stopPropagation() separately if needed.
  • Check: isDefaultPrevented() tells you if it already ran.

One line: preventDefault() means “I will handle this — don’t do the browser’s usual thing.”

Frequently Asked Questions

event.preventDefault() cancels the browser’s default action for the current event — for example, stopping a link from navigating or a form from submitting. It takes no arguments and returns undefined. Available since jQuery 1.0.
Call it when you handle the event in JavaScript and want to replace the native behavior — SPA link clicks, AJAX form submits, custom validation before submit, or any time the default action would interfere with your code.
No. preventDefault() only cancels the default browser action. The event still bubbles to parents unless you also call event.stopPropagation() or return false from a jQuery handler.
In jQuery handlers, return false calls both preventDefault() and stopPropagation(). preventDefault() alone cancels the default action but lets bubbling continue — useful when parent handlers should still run.
No. Once preventDefault() runs on an event dispatch, the default action stays cancelled for that dispatch. Use event.isDefaultPrevented() to check whether it was already called.
It works on cancelable events — click on links, submit on forms, and similar. Some events are not cancelable; calling preventDefault() on them has no effect.

Next: isDefaultPrevented()

Learn how to detect whether preventDefault() was already called.

isDefaultPrevented() tutorial →

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.

10 people found this page helpful