5 ms·
Oh wow, I've been wishing for ages that href were an attribute and not a part of the <a> tag. This is validation that it isn't such a terrible idea after all.
by SquareWheel 14y ago
Oh wow, I've been wishing for ages that href were an attribute and not a part of the <a> tag. This is validation that it isn't such a terrible idea after all.
<img src="pic.jpg" href="about.html">
Doesn't that just look cleaner? Shame it won't change until something radical supersedes HTML.
- Alexandervn 14y agoNo so clean to me, without an 'alt'-attribute..
- tzaman 14y agoalt is beside the point here
- jackalope 14y agoIt's a fair point, though. The href attribute tends be very long, so if your criteria is readability, do you opt for attribute soup or put it in a wrapper div or span? It's a subjective decision, and I don't think there's a right or wrong answer, but examples should reflect real world situations. Either way, I think href should be a universal attribute (obviously, it wouldn't make sense on something like br). It offers a lot of flexibility and is probably no more subject to abuse than anything else. I don't see how browsers would have a problem implementing it. Just look at the 3D view of a complex page in the Firefox Inspector to get an idea of what they're already coping with.
- eli 14y agoI assure you that every useful implementation of an HTML Parser--apart from validation tools--will handle the missing alt just fine, regardless of what the spec says.
- gsnedders 14y agoIt leads to radically different behaviour in screen-readers, at least, and they most certainly are useful implementations.
- Mahn 14y agoWell, theoretically, for a HTML5 standards compliant version you could do: <img src="pic.jpg" data-href="about.html"> And this, plus what I suspect it would be a very tiny global javascript handler that takes care of simulating the links, would pretty much do it. Of course, there is the question of how well this would work on older browsers, although actually as long as javascript is not disabled I don't think it would give much trouble (data attributes can be easily fetched in IE6 for instance) Edit: Here's a quick and dirty demo of how this could work: http://jsfiddle.net/Dszvc/2/ http://jsfiddle.net/Dszvc/2/ it could easily be turned into a full featured plugin.
- olavk 14y agoOnly HTML5 compliant in the sense that it is not illegal. There is no standard semantics for data-attributes, so e.g. Google will not index your links.
- Mahn 14y agoTrue, I didn't consider that. I guess you could work around this placing all the links you want to be indexed in a hidden div or something similar though. This could be automated via javascript aswell.
- olavk 14y agoIt would be a lot simpler just to use a-elements though :-)
- SquareWheel 14y agoThe anchor text and surrounding paragraph of the link is also important for SEO-value, so I'm afraid that would not work. I think the idea of a shiv is a neat one, but unfortunately not very practical at the moment.
- deno 14y agoWould Google index attributes in XLink namespace? E.g.: <img src="pic.jpg" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="about.html" /> I know they index SVG documents, and there’s no @href in SVG namespace… Would that work for (X)HTML5 documents, either served as HTML or XML document? You’d still need JS polyfill, but at least the semantics remain intact.