←back to thread

Just use a button

(gomakethings.com)
284 points moebrowne | 1 comments | | HN request time: 0.202s | 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 #
galaxyLogic ◴[] No.45775591[source]
> they're unaware of the proper way to disable submit behavior.

That is an issue in favor of DIV, you don't accidentally set type="submit" because you don't know about that. There are many things many people don't know.

Using a DIV means you start from empty plate and explicitly add the features you want to add, which makes it easy to later remove or change those features when you want to.

Of course if your knowledge of HTML standards is great and Button exactly fits your current use-case you probably will use it, but designs and requirements change all the time.

Using DIV makes your design more transparent, you see there are certain features you have set to it by adding the attributes.

Using a Button means you (and other people reading your code) probably want to consult documentation to understand what it exactly does. With a DIV + attributes that is explicitly "spelled out".

Just some pros and cons.

replies(9): >>45775691 #>>45775744 #>>45775764 #>>45775783 #>>45775855 #>>45775871 #>>45775913 #>>45776764 #>>45777303 #
1. Sohcahtoa82 ◴[] No.45775871[source]
> Using a DIV means you start from empty plate

When comparing to a Button, that's a bug, not a feature.