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.:
- Which "href" value should I use for JavaScript links, "#" or "javascript:void(0)"?
- Is an empty href valid?
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>
OR
<a href="" class="action"></a>
OR
<a href="javascript;" class="action"></a>
OR
<button class="action"></button>
OR
<span class="action"></span>
WITH (example) ajax call:
<script>
$('.action').click(function() {
$.ajax({
url: "test.html",
context: document.body
})
.done(function() {
$(this).addClass("done");
});
});
});
</script>
As mentioned the restrictions cannot be changed. Period.