jQuery – When to use return false or preventDefault

Ran into a great article that explains the differences between return false, preventDefault and stopPropagation.  Here’s a summary:

  • return false does both preventDefault and stopProgagation
  • preventDefault just stops the browser default event.
  • stopPropagation stops bubbling.

In most cases you would only want to do preventDefault.  If you stopPropagation you prevent your code from being extensible.

 

source:  http://fuelyourcoding.com/jquery-events-stop-misusing-return-false/

Tagged with: ,

Leave a Reply