jQuery event.preventDefault()

Beginner
⏱️ 9 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Event object · jQuery 1.0+

What You’ll Learn

event.preventDefault() cancels the browser’s default action for an event — link navigation, form submit, and more. This tutorial covers the official jQuery demo, SPA links, AJAX forms, conditional validation, and how it differs from stopPropagation() and return false.

01

Method

preventDefault()

02

Returns

undefined

03

Official

Log to #log

04

Links

Block navigate

05

Forms

AJAX submit

06

Since 1.0

No arguments

Introduction

Many DOM events trigger a default browser action — clicking a link navigates, submitting a form reloads the page, pressing Enter in some inputs submits. When your JavaScript should handle the interaction instead, call event.preventDefault().

jQuery has exposed this method since version 1.0 on its normalized event object. The official demo prevents link navigation and appends a message to #log, proving the default click action was cancelled while your handler still runs.

Understanding event.preventDefault()

This method tells the browser: do not perform the native action for this event.

  • Link clicks — stops navigation to the href URL.
  • Form submit — stops the page reload and native POST/GET.
  • No arguments — call it with empty parentheses; returns undefined.
  • Bubbling continues — parent handlers still run unless you also call stopPropagation().
💡
Beginner Tip

Use preventDefault() when you want custom behavior instead of the browser default — not when you want to hide an element or stop other handlers. For the latter, use CSS or stopPropagation().

📝 Syntax

Official jQuery API form (since 1.0):

jQuery
event.preventDefault()
// typical pattern:
$( "a" ).on( "click", function ( event ) {
  event.preventDefault();
  // custom logic replaces navigation
});

Parameters

  • None — this method does not accept any arguments.

Return value

  • undefined — the method cancels default action as a side effect; it does not return a meaningful value. Use event.isDefaultPrevented() to check state afterward.

Official jQuery API example

jQuery
$( "a" ).on( "click", function ( event ) {
  event.preventDefault();
  $( "<div/>" ).append( "default " + event.type + " prevented" ).appendTo( "#log" );
});

⚡ Quick Reference

GoalAPIEffect
Cancel defaultevent.preventDefault()No navigate / no submit
Check if cancelledevent.isDefaultPrevented()Returns Boolean
Stop bubbling onlyevent.stopPropagation()Parent handlers skip
jQuery shorthandreturn falseprevent + stopPropagation
Native equivalentevent.originalEvent.preventDefault()Underlying DOM API

📋 preventDefault() vs stopPropagation() vs return false vs isDefaultPrevented()

Four related tools — cancel default, stop bubbling, jQuery shorthand, or read the flag.

preventDefault
event.preventDefault()

Cancel default action

stopPropagation
event.stopPropagation()

Stop event bubbling

return false
return false

prevent + stopPropagation

isDefaultPrevented
event.isDefaultPrevented()

Read flag (Boolean)

Examples Gallery

Example 1 follows the official jQuery demo. Examples 2–5 cover SPA links, AJAX submit, conditional validation, and preventDefault vs stopPropagation.

📚 Official jQuery Demo

Prevent link navigation and append to #log.

Example 1 — Official Demo: append to #log

Official jQuery demo — on link click, call event.preventDefault() and log that default action was prevented.

jQuery
$( "a" ).on( "click", function ( event ) {
  event.preventDefault();
  $( "<div/>" ).append( "default " + event.type + " prevented" ).appendTo( "#log" );
});
Try It Yourself

How It Works

preventDefault() cancels navigation. Your handler still runs and can update the DOM — the official demo proves both in one click handler.

Example 2 — SPA Link: prevent navigation, show status

Block default navigation and display a status message in the UI.

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

How It Works

Single-page apps intercept link clicks with preventDefault(), then update content or history via JavaScript instead of a full page load.

📈 Practical Patterns

Forms, validation, and propagation behavior.

Example 3 — AJAX Form: preventDefault on submit

Stop native form submit and send data with AJAX instead.

jQuery
$( "#myForm" ).on( "submit", function ( event ) {
  event.preventDefault();
  $.post( "/api/save", $( this ).serialize() );
});
Try It Yourself

How It Works

Without preventDefault(), the browser would navigate or reload. Cancelling submit lets your XHR or fetch handle the response in place.

Example 4 — Validation: preventDefault only when empty

Allow native submit when valid; call preventDefault() only when a required field is empty.

jQuery
$( "#myForm" ).on( "submit", function ( event ) {
  if ( $( "#name" ).val().trim() === "" ) {
    event.preventDefault();
    $( "#error" ).text( "Name is required" );
  }
});
Try It Yourself

How It Works

Conditional preventDefault() is a common validation pattern — block only when input fails your rules, otherwise let the browser default run.

Example 5 — preventDefault vs stopPropagation: parent still runs

Child calls preventDefault() only — parent click handler still fires because bubbling was not stopped.

jQuery
$( "#parent" ).on( "click", function () {
  $( "#log" ).append( "<div>parent handler ran</div>" );
});
$( "#child-link" ).on( "click", function ( event ) {
  event.preventDefault();
  $( "#log" ).append( "<div>default prevented, bubbling continues</div>" );
});
Try It Yourself

How It Works

preventDefault() affects default action only. Use stopPropagation() when you need to block parent handlers — or return false for both in jQuery.

🚀 Common Use Cases

  • SPA routing — intercept link clicks and load views without full page reload.
  • AJAX forms — prevent submit reload and post data with $.ajax or $.post.
  • Custom validation — block submit when fields fail client-side checks.
  • Modal triggers — prevent anchor navigation when href="#" would jump the page.
  • Drag-and-drop UI — cancel default on certain mouse or touch events where needed.
  • Progressive enhancement — only prevent default when JavaScript enhancement is active.

🧠 How preventDefault() Works

1

User action

User clicks a link or submits a form — browser prepares the default action (navigate or reload).

Trigger
2

Handler runs

Your jQuery handler receives the normalized event object and can call preventDefault().

Handler
3

Default cancelled

Browser skips navigation or submit — flag set so isDefaultPrevented() returns true.

Cancel
4

Custom logic wins

Your code updates the DOM, sends AJAX, or shows messages — default action never runs.

📝 Notes

  • Available since jQuery 1.0 — returns undefined.
  • Takes no arguments — call with empty parentheses.
  • Cancels default browser action only — not bubbling or other handlers.
  • Works on cancelable events — click on links, submit on forms, etc.
  • return false in jQuery handlers also calls preventDefault plus stopPropagation.
  • Use event.isDefaultPrevented() (jQuery 1.3+) to verify cancellation in later handlers.

Browser Support

event.preventDefault() is part of jQuery’s normalized event object since jQuery 1.0+. It wraps the native DOM preventDefault() method so cancelling default actions works consistently across browsers jQuery supports, including legacy environments where direct native calls behaved differently.

jQuery 1.0+ · all browsers

jQuery event.preventDefault()

Cancel default browser actions reliably.

100% Universal
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() undefined

Bottom line: Call preventDefault() to cancel — call isDefaultPrevented() to verify.

Conclusion

event.preventDefault() is the standard way to stop the browser from navigating, submitting, or performing other native actions when your JavaScript handles the event instead. The official demo shows it working on link click with a log message.

Pair it with explicit handler logic for SPAs, AJAX forms, and validation — and know the difference from stopPropagation() when parent handlers should still run.

💡 Best Practices

✅ Do

  • Call event.preventDefault() explicitly in new code
  • Use on submit handlers before AJAX replacement
  • Prevent link clicks in SPA routers before updating history
  • Call conditionally — only when validation fails or JS handles the action
  • Check isDefaultPrevented() in cooperative multi-handler setups

❌ Don’t

  • Confuse with stopPropagation() — they solve different problems
  • Use return false when parent handlers must still run
  • Call preventDefault on non-cancelable events expecting a magic fix
  • Prevent every link without a fallback — breaks no-JS users
  • Assume preventDefault stops other handlers on the same element

Key Takeaways

Knowledge Unlocked

Five things to remember about preventDefault()

Cancel default browser actions.

5
Core concepts
02

Returns

undefined

Value
demo 03

Official

Log #log

Demo
form 04

Submit

AJAX forms

Use
05

Not bubbling

≠ stopProp

Compare

❓ 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 an 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 parent elements unless you also call event.stopPropagation() or return false from a jQuery handler.
In jQuery event handlers, return false calls both preventDefault() and stopPropagation(). preventDefault() alone cancels 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. Always handle the specific event type your element fires.
Did you know?

event.preventDefault() has been part of jQuery’s event object since version 1.0 — one of the earliest event methods in the library. jQuery added isDefaultPrevented() in 1.3 so handlers could inspect whether cancellation already happened without reading browser-specific flags directly.

Next: event.isDefaultPrevented()

Check whether preventDefault() was called on the event object.

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.

6 people found this page helpful