Difference between event.preventDefault() and return false in jQuery.

Discussion in 'Design and Graphics' started by sarahjoness, Dec 10, 2015.

  1. sarahjoness macrumors newbie

    Joined:
    Dec 15, 2014
    Location:
    California
    #1
    What's the Difference between event.preventDefault() and return false in jQuery.
     
  2. olup macrumors 6502

    Joined:
    Oct 11, 2011
    #2
    The http://forums.macrumors.com/forums/web-design-and-development.58/ would be the more appropriate forum for this. ;)

    event.preventDefault() cancels the default behavior, submitting a form on click or clicking a link.

    Return false prevents events from bubbling up the DOM tree, therefore could be seen as follows:
    Code:
    function(e) {
      e.preventDefault();
      e.stopPropagation();
    }
    More on events can be read on Peter-Paul Kochs blog: http://www.quirksmode.org/js/events_order.html
     
  3. rochow macrumors member

    Joined:
    Aug 20, 2013
    #3
    You can read into why later; if you're newer to programming just always use preventDefault();
     

Share This Page