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

Jasper Bryant-Greene jasper at bryant-greene.name
Thu Sep 1 15:35:43 PDT 2005


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/



More information about the whatwg mailing list