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

Simon Pieters wrote:
> 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.

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"));

-- 
Jasper Bryant-Greene
Freelance web developer
http://jasper.bryant-greene.name/

Received on Thursday, 1 September 2005 15:35:43 UTC