Just a matter of curiosity, I know it will work, but is it standard-compliant?
I want to use
<a> tag with onclick instead of href action, is it "correct"?
Yes, you can have an anchor tag without a href. After all, anchors are also used to indicate positions in a page. cfr: http://www.w3schools.com/tags/att_a_name.asp
Use both. If, in your onclick event you are linking to another resource (eg. a popup of information) then you should still provide a suitable URI in the
HREF attribute for accessibility (As danwellman suggests:
return false; in the onclick event to prevent the
The problem with using
return false; in your onclick event - but this is still not ideal.
So, best to use both if possible. (But yes, it is still valid HTML to omit the
Some browsers (ahem, IE) fail to render the
pointer cursor on links that don't have
In practice I find it best to include the
href with a hash symbol,
<a href="#">JS Button</a> and either
return false; or use
event.preventDefault(); from the handler rather than omitting the