Its all good! :) I knew that ... no really I mean it! :p -- Brandon Aaron
On 9/27/07, Michael Geary <[EMAIL PROTECTED]> wrote: > > Man, that is some goofy text formatting. I wasn't using larger type for > emphasis or to be shouting - it was just some kind of glitch that didn't > show up in the outgoing message. I've seen it happen before, not sure what > causes it. > > And Brandon, I hope that message didn't come across the wrong way. I was > just having some fun with the concept of a return statement reaching back in > time to affect code that had already executed. :-) > > ------------------------------ > *From:* Michael Geary > Um, Brandon, so what you're saying is that if you comment out the "return > false;" in the first example below (making it the same as cmbtrx's code), it > will fail to display the alert? > > Let's think about this... > > alert() is a blocking call. It opens the alert box immediately, and the > function does not return until you close the box. > > Since the "return false;" is executed *after* the alert(), it seems > unlikely that its presence or absence would affect something that's already > happened. :-) > > The "return false;" does prevent the default action of following the link, > as you mentioned. > > -Mike > > ------------------------------ > *From:* Brandon Aaron > The click event on an A tag has a default action associated with it by the > browser ... more specifically a redirect to the links href. You have to stop > this default action in order to see your alert. There are two ways to do > this. > > The first way: A click handler can return false to prevent the default > (and stop propagation). To do this, your event handler would look like this: > > $("a").click(function(){ > alert("Thanks for visiting!"); > return false; > }); > > The second way: The event handler gets passed the event object as its > first argument and the event object has a method to prevent the default > behavior as well. You could also do the above like this: > > $("a").click(function(event){ > alert("Thanks for visiting!"); > event.preventDefault(); > }); > > Hope that helps! > > -- > Brandon Aaron > >