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