jQuery interview question · Most asked

What is the difference between preventDefault(), stopPropagation() and returning false in a jQuery handler?

Summary

event.preventDefault() stops the browser's default action (following a link, submitting a form); event.stopPropagation() stops the event bubbling to ancestor handlers; returning false from a jQuery handler does both.

Longer Answer

Prefer calling preventDefault() explicitly: return false also stops propagation, which silently breaks delegated handlers and analytics listeners higher up the tree. stopImmediatePropagation() additionally prevents other handlers on the same element from running. In plain DOM addEventListener handlers, return false does nothing.

Key Points

  • preventDefault: no default action.
  • stopPropagation: no bubbling.
  • return false: both (jQuery only).
  • Prefer explicit preventDefault.

More most-asked jQuery questions

← All jQuery questions