←back to thread

Just use a button

(gomakethings.com)
284 points moebrowne | 5 comments | | HN request time: 0.226s | source
Show context
pverheggen ◴[] No.45774978[source]
A good addition to this article is that most buttons should have type="button" on them. By default, buttons are type="submit", which if contained inside a form will submit that form.

I'm sure there are some devs who reach for a div because they're unaware of the proper way to disable submit behavior.

replies(4): >>45775148 #>>45775591 #>>45775683 #>>45775964 #
1. mixmastamyk ◴[] No.45775683[source]
Believe that default is for <input type="submit">, not <button>.
replies(3): >>45775737 #>>45775922 #>>45776810 #
2. pverheggen ◴[] No.45775737[source]
Nope, it's the default:

https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/...

Maybe you’re thinking of <input type=“button”>, which doesn’t submit?

3. cferdinandi ◴[] No.45775922[source]
It's the default for buttons inside forms, but it's SO trivial to add type="button" than any argument that div's are a better choice because of this should be dismissed as unserious trolling out-of-hand.
4. tomkarho ◴[] No.45776810[source]
I seem to recall that once upon a time the default type for a button was in fact "button" but at some point (somewhere in the region of html 5 / es6) it was switched into "submit".
replies(1): >>45781018 #
5. pwdisswordfishy ◴[] No.45781018[source]
The nice thing about actually versioning standards (instead of doing that lazy "living standard" shit) is that you can actually look such things up.

https://www.w3.org/TR/html4/interact/forms.html#adef-type-BU...