2

As I understand it, the < A > tag is the "anchor" tag, and it has three purposes:

1) Describe and name an item on the page <a name="foo"/>

2) Send a user to another page, when clicked <a href="http://www.yahoo.com">Yahoo!</a>

3) Send a user to another spot in the same page, when clicked <a href="#foo">Foo!</a>

It was explained to me that the < a > tag is the only touch/click event universally handled across browsers, and we needed to hijack it for this compatibility. I doubt this - if the browser is capable of displaying a website that uses JQuery (and CSS2/3!), the browser should also be able to handle custom onclick() events without the need of anchor tags.

Right now, it's been standard operating procedure in the project to handle all clickable events with the use of the <A> tag. In code, we must prevent default (otherwise the page jumps to the top), and then handle our merry business. I strongly feel that this is abusing the purpose of the tag, much like how some frameworks hijacked the <i> tag to show icons.

IMO, if you wanted a selectable LI list, you assign an "onclick" event handler to each LI item. Since there's no default action, there is no need to worry about preventing default.

Since this is StackOverflow, I need to have a question to answer: Is this currently prescribed behavior abusing the purpose of the < A > tag?

EDIT: For purposes of accessibility (being able to tab through objects, which A allows but LI does not ), this StackOverflow post of setting TabIndex on an LI seems promising:

What is the HTML tabindex attribute?

Community
  • 1
  • 1
Jeffrey Kern
  • 2,024
  • 20
  • 40

2 Answers2

2

With the use of jQuery you can on('click',callback) any element.

Using only the a element may be for accessibility purposes (telling screen readers, for example, that this element is to do something interesting).

Richard Parnaby-King
  • 14,703
  • 11
  • 69
  • 129
  • I did just check, using the A tag allows you to tab over to items in a customized list, whereas you cannot without it. So it does allow the usage of the site for those without mice or touch input (which is rare but does occur). – Jeffrey Kern Feb 23 '15 at 17:33
  • If accessibility is indeed a concern (and in a lot of cases it simply is not, whether we find that fair or not), you could bind key handlers to the navigation elements. After 20 years coding HTML, I have personally pretty much abandoned HTML tags and use only about 5 or so of them in 99% of the cases: `DIV` for anything to lay out, `A` for some (but not all) clickables, `SELECT` (which is almost extinct IMHO, too), `INPUT`, and now I have to really think about what else... – tim May 13 '15 at 01:23
1

Yes, it is an abuse.

I would explain them about Semantic HTML. Every tag has a purpose and a context where it should be used.

By the way, usage of <i> for icons is not necessarily an abuse. CSS is strongly recommended for italic style.

Community
  • 1
  • 1
Rahul Desai
  • 15,242
  • 19
  • 83
  • 138
  • 1
    @JeffreyKern Use whatever that suits the purpose / context as I mentioned earlier. Use `` where you want to *link* to something. Use `
  • `'s where you want to display a *list*.
  • – Rahul Desai Feb 23 '15 at 17:41
  • @epascarello Please checkout [this](http://stackoverflow.com/questions/15374628/make-html5-css3-website-compatible-with-old-browsers) and [this](http://www.htmlgoodies.com/html5/client/learn-html5-in-5-minutes-backwards-compatibility-for-older-browsers.html#fbid=z3EPKsZcPFB). – Rahul Desai Feb 23 '15 at 17:52
  • @epascarello Sorry, I dont see OP speaking about menu. – Rahul Desai Feb 23 '15 at 17:55
  • whenever I hear people obsessing over semantic HTML, I cringe. Look at many popular sites out there, and you rarely see semantically structured HTML anymore. – tim May 13 '15 at 01:19