-2

Help needed to understand the source code...

I visited the website bseindia.com some time ago and when i was checking for its coding i couldn't understand the action performed when you click on the buttons aligned horizontally at the top (About BSE, Markets, etc). The anchor have href attribute with value only "#". I could use something like that in my upcoming project so i would appreciate some help.

please tell the use of empty "#" in anchor tags href does and if any other language like Server-side etc then please do tell me.

vascowhite
  • 18,120
  • 9
  • 61
  • 77

3 Answers3

1

This is a common practice. Actually these kind of links are used more like "buttons". I mean, the url will not change, but some action will happen, based on the javascript implementation.

Please read this post, to learn more: Which "href" value should I use for JavaScript links, "#" or "javascript:void(0)"?

Community
  • 1
  • 1
Tamás Pap
  • 17,777
  • 15
  • 70
  • 102
0

please tell the use of empty "#" in anchor tags

It is a relative URL to the top of the current page.

If anything else happens when the link is clicked, it is because client-side JavaScript is involved.

Binding JS to links to the top of the page is a common practise, but a poor one. It is neither Progressive nor Unobtrusive.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
0

The # is to keep the styling of the link (I think that is what it is for, not sure). An action takes place because javascript registers event handlers on the link, such as this:

html:

<a href="#" id="test">test</a>

javascript:

document.getElementById('test').onclick=function(){
    alert('you clicked it!');
}

here is a jsfiddle: http://jsfiddle.net/fZ2JQ/

markasoftware
  • 12,292
  • 8
  • 41
  • 69
  • If you think that an answer works and you like it, you should click on the check mark just below the votes of the question (the number with the arrows on the top and bottom). This means that you accept the answer, giving the answerer 15 reputation and you 2 reputation. – markasoftware Mar 30 '13 at 00:25