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
Call it early in the handler when you will handle the action yourself.
Bind the event that has a default (click on links, submit on forms).
In the handler, call event.preventDefault().
Run your own logic (update UI, AJAX, SPA route, validation message).
Optionally check later with event.isDefaultPrevented().
Do not assume bubbling stopped — call stopPropagation() only if you need that too.
Piece
Required?
Role
Cancelable event
Yes
e.g. link click, form submit
event argument
Yes
jQuery event object
preventDefault()
Yes (to cancel)
Blocks the browser default
Custom logic
Optional
What 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
Reference
Cheat Sheet
Keep these facts handy while cancelling defaults.
Topic
Detail
Syntax
event.preventDefault()
Arguments
None
Returns
undefined
Since
jQuery 1.0
Official demo
Link click → log “default click prevented”
Stops bubbling?
No
Check later
event.isDefaultPrevented()
vs return false
return false also stops propagation
Try it
Live Preview
Click the link — navigation is cancelled and a log line is added, like the official jQuery API demo.
Bind submit. Form submit is the event with a default reload.
Cancel.preventDefault() keeps you on the page.
Read.serialize() shows what would have been posted.
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");
}
});
default prevented, bubbling continues
parent handler ran
How It Works
Child. Link click calls preventDefault() — no navigation.
Bubble. The same click still reaches #parent.
Both lines. Child and parent messages both appear.
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().
Compatibility
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 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()1.0+
Bottom line: Safe for production. Use it to replace native link/form behavior; pair with isDefaultPrevented() and stopPropagation() when needed.
Analysis
Performance Notes
Approach
Cost
Best for
event.preventDefault()
Negligible
Any cancelable event
Prevent on every click
Fine
SPA links / custom UI
Heavy work after prevent
Can lag
Keep post-cancel work lean
return false always
Fine
Only when you also want to stop bubble
Calling preventDefault() is cheap. Cost comes from the custom logic you run afterward — keep that focused.
Remember
Key Takeaways
Role: cancel the browser’s default action for this event.
Common uses: links that should not navigate; forms that should not reload.
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.