event.preventDefault() — cancels the browser’s default action (link navigation, form submit), while the event still propagates.event.stopPropagation() — stops propagation through the tree (bubble/capture), while the default action remains.preventDefault doesCancels the element’s default behavior:
href.The event still propagates, so parent handlers will run.
Mini example:
// Link won’t navigate; parent handler still runs
parent.addEventListener('click', () => console.log('parent'));
link.addEventListener('click', (e) => {
e.preventDefault();
console.log('link');
});stopPropagation doesStops further propagation (down the capture phase or up the bubble phase). The default browser action is not canceled.
Mini example:
// Click on button doesn’t reach parent; the button’s default action remains
card.addEventListener('click', () => console.log('card'));
button.addEventListener('click', (e) => {
e.stopPropagation();
console.log('button');
});stopPropagation does not cancel the default action — use preventDefault.preventDefault does not stop propagation — use stopPropagation.event.stopImmediatePropagation().If a nested link inside a card should:
preventDefault),stopPropagation),call both:
link.addEventListener('click', (e) => {
e.preventDefault();
e.stopPropagation();
});In React’s synthetic events these methods behave like DOM:
e.preventDefault() — cancels the action.e.stopPropagation() — halts propagation.
Remember onClickCapture runs in the capture phase before onClick.