Is there any use to return values from .click()
and .change()
handlers (like return true
or return false
)?
Asked
Active
Viewed 2.6k times
40
-
1How do you mean? Show us an example of how you would like to use that result (the return value). – Peter Örneholm Dec 07 '10 at 17:07
-
1Just curious since some return true others false and I couldn't find anything in the docs. – Buzzzz Dec 07 '10 at 21:27
2 Answers
51
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.

Peter Bailey
- 105,256
- 31
- 182
- 206
-
stopPropagation is only for jQuery event handlers (but jquery event handler was the question) – melutovich Oct 30 '21 at 18:35
23
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).

jwueller
- 30,582
- 4
- 66
- 70
-
3In that case, jQuery is taking liberties here: for non-jQuery event handlers, `return false` only prevents the default action and does not stop the event from bubbling. – Tim Down Dec 07 '10 at 17:19
-
-
@TimDown To clarify, by "non-jQuery event handlers", do you mean handlers that were attached by other means than the jQuery methods (.on or .live/.bind/.delegate), like addEventListener? – Jo Liss Nov 28 '11 at 14:29
-
5@JoLiss: `return false` has no effect in event listeners attached using DOM's `addEventListener()`. It works to suppress default behaviour in so-called DOM0 event handlers, such as `document.body.onclick = function() { return false; };` – Tim Down Nov 28 '11 at 14:54
-
By default, a plain `return` (with no specified return value) or just "falling off the edge of the function"-returning will cause the function to return `undefined`. How does jQuery react to this? – zrajm Jul 15 '19 at 17:31