“return false” seems to work in the submitHandler but I’m not sure why.
function submitHandler() {
$.post($(this).attr('action'), $(this).serialize(), null, "script");
return false;
}
$(document).ready(function () {
$('#top_cat').submit(submitHandler);
$("#tip_click").click(function() {
$("#high_hat").submit(submitHandler);
});
});
I’m also not sure if I need to add a “return false” in the #tip_click function so that it reads like this:
$("#tip_click").click(function() {
$("#high_hat").submit(submitHandler);
return false;
});
What’s the rule to follow here regarding when to “return false“?
You should
return falsewhen:You want to prevent the default event action
onsubmitevent for example, the default action of this event is send the form data to the server, or anonclickevent on an anchor element, the default event action is to follow the anchor’s HREF.You want to stop the event bubbling.
Returning false from an event handler, is like executing both
event.preventDefault();andevent.stopPropagation();.