0

I am parsing a HTML file and I noticed that there is one element that reads:

<a id="someID" class="someClass" href="#" style="someStyle">

Can I please ask what this href="#" lead to?

Barmar
  • 741,623
  • 53
  • 500
  • 612
Yu Zhang
  • 2,037
  • 6
  • 28
  • 42

2 Answers2

2

It doesn't go anywhere. This is a common placeholder for links that are implemented using Javascript. Another popular style is href="javascript:void(0)"; void() is a function that does nothing. Finally, the Javascript function that's run when you click on it could use event.preventDefault() to prevent the normal action of following the link. But you should still put a placeholder in the href, so that when the user hovers over the link it won't show a target in the browser's status line.

Barmar
  • 741,623
  • 53
  • 500
  • 612
  • It goes to the start of the document, when JavaScript is disabled. This is one of the reasons why the syntax should be avoided, see http://stackoverflow.com/questions/134845/href-attribute-for-javascript-links-or-javascriptvoid0/138233#138233 – Jukka K. Korpela Nov 02 '14 at 07:54
1

I generally use '#' to a trigger a JavaScript which works with CSS or page layout. In whole, its just a way to make a dead-link(not leading to any page) which you can use to call various webpage activites like JS or CSS.

Gavin
  • 321
  • 2
  • 10