Take the 2-minute tour ×

Because of business rules and requirements, I need an element that is tab-able (without the use of tabindex), looks like a link, only has javascript functionality (it needs to make an ajax call to a web service for instance) and it cannot contain any special character such as '#' because the url will have that at the end and that will be blocked by our firewall which is set very strict due to external regulations. Also the href cannot be empty because of our web site resides inside Sharepoint and keeping it empty means that you are redirected to the default landing page.

I've come across various questions which all contain some truth and arguments to use one element over the other, but none of those questions contained a satisfying answer, if it even had a marked answer. E.g.:

those two examples are not completely satisfying because for the first one, eventhough one answer has a high amount of votes but I'm not sure if that answer meets the above requirements. the second one for the same reason really.

In summary, which of the below options is preferred, keeping the restrictions and requirements in mind as well as known best practices for semantics and javascript?

<a href="javascript:void(0)" class="action"></a>  


<a href="" class="action"></a>


<a href="javascript;" class="action"></a>


<button class="action"></button>


<span class="action"></span>

WITH (example) ajax call:


    $('.action').click(function() {
            url: "test.html",
            context: document.body
            .done(function() {


As mentioned the restrictions cannot be changed. Period.

share|improve this question

closed as primarily opinion-based by Doorknob, Mathletics, Stewie, Mike, cheesemacfly Jun 26 '13 at 19:29


You should follow the semantics - since it has a click, most likely it is a link or a button. –  fotanus Jun 26 '13 at 16:53
Ok, but which one is your preferred choice from the above suggestions? –  reaper_unique Jun 26 '13 at 16:54
And what's your question? Best practise always is to have an actual, working URL as fallback. Btw, you forgot to e.preventDefault() in your handler –  Bergi Jun 26 '13 at 16:55
If you don't explain why the answers on the other questions didn't satisfy you, this question is invalid and should be closed as a duplicate. Btw, starting a bounty might have been the better choice –  Bergi Jun 26 '13 at 16:57
Firewalls that don't allow # in URLs... that's especially interesting since # is never sent to the server in a request in the first place. You say you cannot change your requirements, but I'm wondering if some of these restrictions exist in the first place. Can you elaborate a bit? –  Brad Jun 26 '13 at 17:00

3 Answers 3

up vote 2 down vote accepted

I remember once a teacher told me that the best was to use a <a> tag ahd the href should point to a page that probably does the exact same thing as the javascript event. So if for any reason the javascript is desactivated on the browser, the user could still use the website as any normal website... but well that works fine on papers... but it would be hard to implement.

If you add javascript code on the href or onclick your user wont be able to open the link on a new tab (by using the middle button or with the context menu)... I personally hate that on a website... links should be used to "link" pages.. not to make javascript changes on the current page, so a <button> seems more semantic to me...

You should also consider SEO (maybe) because robots will try to follow your links to index pages, but they wont follow buttons. Seo is a gray area, but i'd not be surprised if the robots have a max limit of links to follow.. and if your page has lots of links that are used only for js, maybe the robots are not able to correctly index your site

Finally, I rather have unobtrusive Js, so I really try to separate behavior from presentation. I find it ugly when i see html and js together

So i'd go with:

<button class="action"></button>

with an event listener on JS... hey.. but that's just me :)

Hope this helps

share|improve this answer
As this question is now closed and I spend more time reading other answers in other questions I've decided to mark this answer as the correct one as it will be the one I will be implementing. All the items on our site are in fact elements that act like a button but are disguised as links. As it's possible to style a button like a link in all browsers (even IE7), I'm going to do just that. Thank you for the answers even though it was closed due to this being an opinion based question. If for some reason something goes wrong my second option will be <a href="javascript:void(0)"></a>. –  reaper_unique Jun 26 '13 at 19:53

Personally, I like to use <a href="javascript:void(null);"> for my JavaScript-powered links. I know it's overkill, I know that javascript:; would be just as sufficient, but it's a habit I picked up.

That said, if the JavaScript has a non-JavaScript alternative (such as a link that might take you to a form, that has JavaScript to pop up the form in a dialog), I would use that as the href and make sure to prevent the default action in the event handler.

<button> is not a good idea unless you specifically want it to look like a button - depending on your site, this may be a good or bad thing, but you get a lot more freedom by using <a> and CSS.

share|improve this answer

'a' tag with any href you want + event.preventDefault() on onclick function can help you, I think. Why 'a', becouse it good for styling you tabs headers, for example

share|improve this answer
