Live data from Hacker News

The Difference Between a Button and a Link

unplannedobsolescence.com

1–10 of 55 posts

Re: The Difference Between a Button and a Link

#2
You can have button actions today by wrapping the button in a form tag. The article even shows this. The implication seems to be somehow that this is no good because what if you're already in a form tag? The answer is to move the two actions which aren't actually related to the form outside of the form tag and give them their own unique form parents.

Re: The Difference Between a Button and a Link

#4
> Buttons regularly perform navigations. Clicking a logout button navigates the current page to a logged-out one; clicking a “search” button navigates the current page to the query results.

This seems to conflate appearance with semantics. If an element causes a navigation, I make it a link. Whether it looks like a button is irrelevant, that’s CSS.

I always choose one or the other by intended behavior first, and that always works out great.

That said, I like the idea.

Re: The Difference Between a Button and a Link

#7

> Buttons regularly perform navigations. Clicking a logout button navigates the current page to a logged-out one; clicking a “search” button navigates the current page to the query results. This seems to conflate appearance with semantics. If an element causes a navigation, I make it a link. Whether it looks like a button is irrelevant, that’s CSS. I always choose one or the other by intended behavior first, and that…

Imagining you have a navigation to “/logout” that server side invalidates your token and redirects to home, would you implement that as a link? If so, what happens if someone tries to “open in a new tab” it?

Re: The Difference Between a Button and a Link

#8

> Buttons regularly perform navigations. Clicking a logout button navigates the current page to a logged-out one; clicking a “search” button navigates the current page to the query results. This seems to conflate appearance with semantics. If an element causes a navigation, I make it a link. Whether it looks like a button is irrelevant, that’s CSS. I always choose one or the other by intended behavior first, and that…

Well, the idea here is “things that look like buttons do page navigation.”

And the proposal is that we should more closely align the presentation and function.

You are correct that if you don’t care about alignment, there is nothing wrong with the status quo.

Re: The Difference Between a Button and a Link

#9

You can have button actions today by wrapping the button in a form tag. The article even shows this. The implication seems to be somehow that this is no good because what if you're already in a form tag? The answer is to move the two actions which aren't actually related to the form outside of the form tag and give them their own unique form parents.

And don't forget about the `form` attribute to associate a button with any arbitrary form element by ID.

Re: The Difference Between a Button and a Link

#10

You can have button actions today by wrapping the button in a form tag. The article even shows this. The implication seems to be somehow that this is no good because what if you're already in a form tag? The answer is to move the two actions which aren't actually related to the form outside of the form tag and give them their own unique form parents.

I had the same thought at first, but the example in the article convinced me. It's something I ran into when I did webdev.

Form tags usually contain other elements - textboxes, checkboxes, etc. The url and method are specified on the form tag and not the button, so if you want a second submit button that goes to a different URL or use a different method, you need to duplicate all the other inputs in a separate form tag with your button.

All of this can be done with scripting, but the point of this proposal is to make that unnecessary.

Post reply on HN