RE: [TECHS] Use of anchor tags to invoke JavaScript

I can think of one more:
<a href="javascript:void(doSomething());">Action Link</a> ...which
should prevent the browser from doing *anything* but run the code...
assuming it has javascript support, of course.  I'd have to think about
which method is best.
-----Original Message-----
From: [] On
Behalf Of Isofarro
Sent: Thursday, 18 August 2005 4:27 AM
Subject: Re: [TECHS] Use of anchor tags to invoke JavaScript wrote:
> <andrew wrote>
> Why not:
>  <a onclick="doSomething();return false;">Action link</a>
> I don't know what different user agent would do with this.  It is 
> possible that it wouldn't be in the tab order unless a tabindex was
> added.  Just a thought...
> </andrew>
> Good idea since href is not a required attribute. But,  as you
> the anchor is not in the tab order if there is no href.   Adding the 
> tabindex="0" attribute did not solve the problem since older browsers 
> did not include it in the tab order thus there is no keyboard focus. 

Thinking about it logically, the a element serves two purposes:
* to add a hyperlink to another document or a point inside the same
* to be a destination for a hyperlink.

The first is accomplished using an href attribute.

The second doesn't and shouldn't by default do anything if activated. 
Its a destination, so using the name attribute gets that done. This has 
largely been superceded with the more modern id attributes on elements.

Trying to put a tabindex on an anchor with no href attribute just 
strikes me as fighting against HTML instead of working within it.


Received on Tuesday, 23 August 2005 02:52:32 UTC