[whatwg] [WA1] The a element could be empty

Matthew Raymond mattraymond at earthlink.net
Fri Sep 2 11:29:35 PDT 2005


Simon Pieters 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>
> 
> How is an empty span less harmful than an empty a element without an href 
> attribute?

   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.

>>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"));
> 
> For keyboard access, you need a tabindex="0" which has no effect in legacy 
> UAs, and you currently can't trigger the click event from keyboard in IE6 or 
> Firefox on a span element.
> 
> The javascript: URI scheme is a separate issue. If we replace the href with 
> "http://example.org/" -- or "mailto:me at example.org", or "data:,foo", or 
> whatever -- in my first example, I would still like to use an empty a 
> element in the markup.

   I don't understand why you couldn't just use styling to make an <a>
element "display: inline" for screen media and "display: none" for print
media. Inserting the contents into <a> and establishing an |onclick|
event means that you'll have to turn right around and use proprietary
events like |onbeforeprint| and |onafterprint| to deal with the extra
<a> element so that it won't be seen when you print.

   So the questions are:

1) Why wouldn't you want the content in the element to be inserted by
Javascript when the page loads when you can just include the content in
markup and hide it using CSS?

2) Even if some of your users don't have support for CSS, why would you
choose to insert content via Javascript when such inserting doesn't
change the fact that you're going to have to remove the content before
printing?

3) How does your original example even prevent the content from being
viewed when printing?

4) What prevents you from inserting the entire <a> element into a <span>?

5) How to you get rid of styling for the <a> element if all <a> elements
 are styled in such a way that they are easily visible even when they
have no contents?

   The bottom line is that you need a much better use case.



More information about the whatwg mailing list