←back to thread

Just use a button

(gomakethings.com)
284 points moebrowne | 8 comments | | HN request time: 0.954s | source | bottom
1. giancarlostoro ◴[] No.45774524[source]
Weird, I always use buttons when I can, unless what I need is not actually a button, but something that performs and on-click sort of like a button, like a hyperlink that navigates you through the web app.
replies(2): >>45774943 #>>45775773 #
2. ervine ◴[] No.45774943[source]
I guess if it doesn't update the url, it's a button.

If it changes the url, it should be a link. At least that's how I've always done it.

replies(1): >>45775119 #
3. cassepipe ◴[] No.45775119[source]
Is is not okay to wrap a link inside a button ? I guess not

Which elements are allowed to wrap which is unclear to me

replies(3): >>45775243 #>>45775937 #>>45776709 #
4. stevula ◴[] No.45775243{3}[source]
What is the use case? It’s hard for me to think of a reason you’d want to wrap a link in a button. If you want to navigate, use an anchor. If you want to trigger JS logic, use a button with onclick handler. If you want to navigate while doing some side effect like an API call, use an anchor with onclick handler (and don’t prevent default).
5. Zak ◴[] No.45775773[source]
> like a hyperlink that navigates you through the web app

You mean an <a> tag?

replies(1): >>45777854 #
6. cferdinandi ◴[] No.45775937{3}[source]
Literally absolutely never ever do this.
7. Shog9 ◴[] No.45776709{3}[source]
FWIW, you can generally figure out what's allowed fairly quickly by checking the content model for a given element[1]. Some browsers might be more or less restrictive, but for normal usage this'll be more than enough to avoid unexpected behavior.

[1]: https://html.spec.whatwg.org/#the-button-element:concept-ele...

8. array_key_first ◴[] No.45777854[source]
Well it might be a SPA so it's not a real link but rather just a function call + pushing some stuff to history and updating the URL (if you're lucky!)