Why using anchors as buttons sucks
plus.google.com
plus.google.com
We use anchor tags as buttons any more because clicking on buttons should (eventually) change the href.location. That means, yes, right-click should work just fine, opening up a new window with your action applied to the current state. Don't look at buttons like Javascript events. Rather look at them like code that changes the URI that then kicks off Javascript events. It's a subtle difference, but it's very important. An anchor as a button isn't the same as a button because they're two completely different things. Your mental model of each should be different.
I don't see where there's much of a mystery or rant here, but maybe I missed it.
Once someone brought up the keyboard issue in my pull request, I researched for a while, and then made the post once I angrily realized the full extent of the problem.
If you need an example app that uses both buttons and links, here: https://chrome.google.com/webstore/detail/mghenlmbmjcpehccoa...
Of course, I'm indubitably in a tiny minority, but it's still something to note.
Notable examples of this include the Facebook "Show more comments" link, g-mail's email links and "Add to Cart" buttons which redirect away from the product page.
Funny enough, the google plus linked above is horrible at this.
That doesn't make any sense. First, the current page doesn't matter. Secondly, "doing something" doesn't define what "something" is. Finally, your complaint is having to click on the button, implying that you have to click on a button to activate it.
Sorry, your just being very confusing, using words and terminology you don't seem to be familiar with.
I meant navigating in the sense of moving the viewport and mouse around a static page rather than moving from page to page.
On a related note, I wonder how screenreaders handle buttons? I'm guessing/hope they read the labels, but if they don't...
Better yet, add a href='/uri/to/script' as a fallback in case the user has JS disabled.
The href is not only for JS-less browsers, it's also for links opened in new tab or saved in browsing session.
By stopping propagation, you break delegation and make it impossible at worst and very random at best to add another handler to the same event.
Just use preventDefault o stop the browser from following the link.
Returning false is equivalent to calling both preventDefault()
(that's what you want) AND stopPropagation()
This is so in jQuery. In basic Javascript "return false" does not stop the propagation. See http://stackoverflow.com/questions/1357118/javascript-event-...Especially since I looked over the pull request he mentions and the explanation as to why href="#" is used is right there in front of his face.
Plus, what's with all the hate for href="#"? Are some people so anal about their code they can't leave one simple little thing in place that makes life easier for them?
Of course I understand why keyboard accessibility (a benefit of href="#") is a good thing, that was a main point in the post: There's no solution for adding "buttons" (in the functionality sense) that look like standard links without major drawbacks, like a lack of keyboard control.
This doesn't feel a very comprehensive or well researched post, especially as you didn't know about e.preventDefault() which afaik is standard practice these days, seems a fairly ballsy thing to ask bootstrap to do when you don't really seem to know much about it.
Then again I guess if you don't question these things, you never find out!
I know what e.preventDefault() is and when and how to use it, just simply didn't think of it when trying to find solutions. It was promptly pointed out in the G+ comments, but there are still major drawbacks to that approach.
Either way, it was well past the asking Bootstrap to add this phase by the time I wrote the post.