jQuery event.preventDefault() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Events

Definition

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().

Syntax

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

jQuery
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
CallWhat it does
Cancelable evente.g. link click, form submit
event argumentjQuery event object
preventDefault()Blocks the browser default
Custom logicWhat you do instead

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

Parameters

ParameterDescription
Step 1Bind the event that has a default (click on links, submit on forms).
Step 2In the handler, call event.preventDefault().
Step 3Run your own logic (update UI, AJAX, SPA route, validation message).

Return Value

Return ValueDescription
Value / undefinedGetters usually return a value from the first matched element, or undefined when nothing applies.

jQuery Examples

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.

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).

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.

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: event.isDefaultPrevented() Method

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

event.isDefaultPrevented() 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.

10 people found this page helpful