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

Hi,

>    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.

The spec says[1],

|If the a element has no href attribute, then the element is a placeholder
|for where a link might otherwise have been placed, if it had been relevant.

Why must a placeholder have contents?

> > 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.

My conserns has nothing to do with printing in itself, or what is displayed 
on the screen vs. the paper. I merely want a blank <a/> to be allowed, if 
the href attribute is not set.

>    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?

I don't want to hide it, I want it to be non existent when scripting is 
disabled or non-supported.

>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?

I don't want to remove it before printing.

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

It doesn't.

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

It's more code, and an empty <a/> is IMHO equally harmful as an empty 
<span/>, so I can use the a element directly.

>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?

By using ":link, :visited" as selector.

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

Ok.

A link to select all text in a textarea:

|  <p>Sample code: <a id="sel"></a> <textarea>...</textarea></p>
|  <script>
|   var elm = document.getElementById("sel");
|   elm.appendChild(document.createTextNode("select all"));
|   elm.href = "javascript:selectall()";
|   function selectall(){...}
|  </script>

A link to an application that requires javascript to be enabled:

|  <p>This application requires javascript. <a id="proceed"></a></p>
|  <script>
|   var elm = document.getElementById("proceed");
|   elm.appendChild(document.createTextNode("Proceed"));
|   elm.href = "the-app.html";
|  </script>

Regards,
Simon Pieters

[1] http://whatwg.org/specs/web-apps/current-work/#the-a

Received on Saturday, 3 September 2005 04:30:58 UTC