<button onclick="alert('Hello'); return false;">Hello</button>
What is the return false part supposed to do? Also, what would return true do if it were there?
The return false
will disregard default behavior for the onclick
event. So, for example, if you had a link:
<a href="http://stackoverflow.com" onclick="alert('Hello'); return false">Link<a>
when the user clicks on the link they'd get a popup but wouldn't actually go the target of the link.
The default button type is submit
, so <button>
is the same as <button type="submit">
(except on IE). The return false
stops the default button action so it will stop form submission from happening.
You can avoid that by defining the button type explicitly
<button type="button" onclick="alert('Hello');">Hello</button>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With