[whatwg] [WA1] The a element could be empty
Ian Hickson
ian at hixie.ch
Wed Oct 31 02:45:51 PDT 2007
On Thu, 1 Sep 2005, Simon Pieters wrote:
>
> The spec currently says[1]:
>
> |The a element must not be empty.
>
> I think it would be more useful if it was changed to:
>
> |If the a element has an href attribute set, then the element must not
> be empty.
>
> It is easier to use an empty a element as a placeholder to grab and use
> with scripts later on, for instance:
>
> <a id="print"></a>
>
> With:
>
> var elm = document.getElementById("print");
> elm.href = "javascript:window.print()";
> elm.appendChild(document.createTextNode("Print this page"));
>
> ...rather than to create the link with script from scratch.
The spec now doesn't say this at all, though there is a general
"should"-level requirement that encourages elements like this not to be
empty. Is that ok?
On Fri, 2 Sep 2005, Jasper Bryant-Greene wrote:
>
> Since that's not actually a link (the href points to the javascript: URL
> scheme which is an ugly hack), what's wrong with:
>
> <span id="print" class="link"></span>
>
> Where the link class may be styled to look like a link with CSS, and
> then
>
> var elm = document.getElementById("print");
> elm.onclick = window.print;
> elm.appendChild(document.createTextNode("Print this page"));
<span>s aren't links, so you can't do things like focus them, tab to them,
etc. You also can't have the fallback of a real page (really the better
design is an <a> that has a link to a page that is equivalent to running
the script on it, and then have the script in an onclick="").
On Fri, 2 Sep 2005, Matthew Raymond wrote:
>
> An empty <a> element is semantically meaningless. By contrast, <span> is
> already defined as having no semantics and empty <span> elements are
> commonly used for styling purposes.
I think this misses the point here.
(Also, <a> is no longer meaningless, it is explicitly defined as a
placeholder for where a link would have been.)
--
Ian Hickson U+1047E )\._.,--....,'``. fL
http://ln.hixie.ch/ U+263A /, _.. \ _\ ;`._ ,.
Things that are impossible just take longer. `._.-(,_..'--(,_..'`-.;.'
More information about the whatwg
mailing list