I have seen the following href used in webpages from time to time. However, I don’t understand what this is trying to do or the technique. Can someone elaborate please?
<a href="javascript:;"></a>
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
An
<a>element is invalid HTML unless it has either anhrefornameattribute.If you want it to render correctly as a link (ie underlined, hand pointer, etc), then it will only do so if it has a
hrefattribute.Code like this is therefore sometimes used as a way of making a link, but without having to provide an actual URL in the
hrefattribute. The developer obviously wanted the link itself not to do anything, and this was the easiest way he knew.He probably has some javascript event code elsewhere which is triggered when the link is clicked, and that will be what he wants to actually happen, but he wants it to look like a normal
<a>tag link.Some developers use
href='#'for the same purpose, but this causes the browser to jump to the top of the page, which may not be wanted. And he couldn’t simply leave the href blank, becausehref=''is a link back to the current page (ie it causes a page refresh).There are ways around these things. Using an empty bit of Javascript code in the
hrefis one of them, and although it isn’t the best solution, it does work.