From what I understand, in HTML5 we're supposed to start using the id
attribute to reference a
elements, instead of the name
attribute. The problem with this is that there is also a constraint that id
should be unique per document.
Now, I see a lot of situations where you'd want to reference a set of related a
elements (in JS, typically). By getting rid of the name
attribute though, we're forced to either reuse the same id
, or use a class
name. Classes should supposedly be about presentation, so this is also an imperfect solution if you're referencing your a
's for non-presentation related reasons.
I suppose another HTML5 alternative would be to use something like data-name
, but this also seems hackish. Is there something I'm missing? Is there a secret W3 conspiracy to phase out name
altogether?
Ah, HTML. How inconsistent you are.
The issue, it seems, is the confusion with
name
attribute for anchors and thename
attribute for inputs. Back in the pre-HTML5 days, you needed a way to distinguish an outgoing link (one viahref
) with an internal document link (a#
bookmark).So, how would they accomplish this? It's specified here: http://www.w3.org/TR/html401/struct/links.html
Yes, give an anchor a
name
attribute (which acts as a fragment identifier) which another anchor couldlink
to.Only, with HTML5, they decided any element (other than
a
) could act as fragment identifier (which makes sense - there should only be one fragment that you can link to...) - Which is why they deprecated thename
attribute.As for how to select them? The
class
attribute is perfectly fine (sure, it's used for styling, but does it make it purely presentational?)Another quote (from w3c: http://www.w3.org/TR/html401/struct/global.html#adef-class)