Jquery Event Handlers Return Values

Is there any use to return values from .click() and .change() handlers (like return true or return false)?

2

2 Answers

return false; will stop the event from bubbling up AND suppress the default action.

In otherwords, returning false is analogous to these two lines

event.stopPropagation();
event.preventDefault();

For events that bubble and are cancelable, at least.

1

return false in such a handler results in event.stopPropagation() (only for jQuery event handlers, as Tim Down suggested in the comments) and event.preventDefault() being called automatically by jQuery.

return true is the same as returning nothing (no action is taken by jQuery).

5

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Sophia Al-Mansoor

Sophia Al-Mansoor

Global Business & E-Commerce Reporter

Sophia analyzes international trade, startup ecosystems, retail transformation, and supply chain logistics for modern digital publications.

Share this article
Twitter Facebook Pinterest