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
Fundamentals
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.
Concept
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().
Foundation
📝 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.
#log shows both:
"default prevented, bubbling continues"
"parent handler ran"
Link does not navigate
How It Works
preventDefault() affects default action only. Use stopPropagation() when you need to block parent handlers — or return false for both in jQuery.
Applications
🚀 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.
Important
📝 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.
Compatibility
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 ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll modern versions
Full support
preventDefault()undefined
Bottom line: Call preventDefault() to cancel — call isDefaultPrevented() to verify.
Wrap Up
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.
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
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about preventDefault()
Cancel default browser actions.
5
Core concepts
stop01
preventDefault
Cancel default
API
∅02
Returns
undefined
Value
demo03
Official
Log #log
Demo
form04
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.