-2

I found this code and I'm wondering why is set to return false?

    $("#_plan").on('click', function() {
    showChoose();
    return false;
});
user5372
  • 177
  • 8
  • It makes sense for a form but not for a button: http://stackoverflow.com/questions/3569072/jquery-cancel-form-submit-using-return-false – Blauharley Jan 27 '15 at 08:12

1 Answers1

4

Returning false from the click handler prevents the default action from execution. For example if #_plan is a submit button or an anchor returning false will prevent the browser from redirecting away from the current page (which is what happens when you submit a form or click on an anchor).

As an alternative you could use the following:

$("#_plan").on('click', function(evt) {
    evt.preventDefault();
    showChoose();
});

This way the browser will remain on the same page and leave time for the showChoose function to execute.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928