[jQuery] Re: Any benefit to using event.preventDefault() over return false to cancel out an href click?

2009-04-20 Thread John Resig

return false does e.preventDefault() and e.stopPropagation().

--John



On Mon, Apr 20, 2009 at 3:20 PM, kgosser kgos...@gmail.com wrote:

 Just curious if there is a best practice when choosing between

 $(a).click(function(){
   // stuff
   return false;
 });

 and

 $(a).click(function(){
   // stuff
   event.preventDefault();
 });

 to cancel out the href of an anchor when clicked.

 Thanks in advance for the help.


[jQuery] Re: Any benefit to using event.preventDefault() over return false to cancel out an href click?

2009-04-20 Thread kgosser

Thanks, John.

So is it advisable to use one form or another?

I've used return false throughout my app, and I'm trying to decide if
it's a best practice to change it to preventDefault() if it's wiser to
do so.

On Apr 20, 2:26 pm, John Resig jere...@gmail.com wrote:
 return false does e.preventDefault() and e.stopPropagation().

 --John

 On Mon, Apr 20, 2009 at 3:20 PM, kgosser kgos...@gmail.com wrote:

  Just curious if there is a best practice when choosing between

  $(a).click(function(){
    // stuff
    return false;
  });

  and

  $(a).click(function(){
    // stuff
    event.preventDefault();
  });

  to cancel out the href of an anchor when clicked.

  Thanks in advance for the help.


[jQuery] Re: Any benefit to using event.preventDefault() over return false to cancel out an href click?

2009-04-20 Thread Josh Powell

It sounds like John is saying that

e.preventDefault() will prevent the default event from occuring and
e.stopPropogation() will prevent the event from bubbling up and
return false will do both, so

If you only want to stop the default but allow propogation or vice
versa, then use the methods, otherwise use return false to do both.

On Apr 20, 1:01 pm, kgosser kgos...@gmail.com wrote:
 Thanks, John.

 So is it advisable to use one form or another?

 I've used return false throughout my app, and I'm trying to decide if
 it's a best practice to change it to preventDefault() if it's wiser to
 do so.

 On Apr 20, 2:26 pm, John Resig jere...@gmail.com wrote:

  return false does e.preventDefault() and e.stopPropagation().

  --John

  On Mon, Apr 20, 2009 at 3:20 PM, kgosser kgos...@gmail.com wrote:

   Just curious if there is a best practice when choosing between

   $(a).click(function(){
     // stuff
     return false;
   });

   and

   $(a).click(function(){
     // stuff
     event.preventDefault();
   });

   to cancel out the href of an anchor when clicked.

   Thanks in advance for the help.