10

If I'm using an <a> tag click event to trigger an ajax call, and I don't want the link to physically go anywhere, what is the correct value for the href attribute?

Is it '#' or just leave it empty?

(I understand the accessibility issues that this brings).

Chris J Allen
  • 18,970
  • 20
  • 76
  • 114
  • 2
    You can also use `javascript:void(0)` Look at this [question](http://stackoverflow.com/questions/134845/href-attribute-for-javascript-links-or-javascriptvoid0) – Jack Pettinger Apr 05 '13 at 07:58
  • 2
    In my opinion the "correct" `href` is a full url that does something equivalent to the Ajax call, or at worst directs users to a "Sorry, this page doesn't work without JavaScript" page. That way users with JS enabled just get the Ajax (you'll prevent the default navigation from your click handler), but users with JS disabled still get something. – nnnnnn Apr 05 '13 at 08:05
  • @nnnnnn, Please write it as an answer! – gdoron Apr 05 '13 at 10:09
  • @gdoron - Nah, I don't feel right posting an answer on a question that I voted to close (as a duplicate). – nnnnnn Apr 05 '13 at 10:25

2 Answers2

3

Better be # because some browsers won't render <a> with empty href(for example Google chrome will render the anchor as a plain text).

gdoron
  • 147,333
  • 58
  • 291
  • 367
2

Empty is valid.

Although standard practice is to use "#"

Mathew Thompson
  • 55,877
  • 15
  • 127
  • 148