I wanna know what javascript:;
does in the following code:
<a href="javascript:;" id="notifications-handler">0</a>
I can't anything useful in Google so I wanted to ask you here.
I wanna know what javascript:;
does in the following code:
<a href="javascript:;" id="notifications-handler">0</a>
I can't anything useful in Google so I wanted to ask you here.
As a URL? It doesn't do anything. It's a convenient way of making the target of a clickable widget on a web page not do anything at all.
If it had actual Javascript code between the javascript:
and the ;
, then it would do whatever that code said to do.
Assuming you mean <a href="javascript:;">xxx</a>
, it's a way to make the link not do anything, but continue to behave like a link.
As you know, in links, the first bit can be a protocol, like http:
or https:
or ftp:
or mailto:
. javascript:
is a pseudo-protocol that says "Treat the rest of this link as JavaScript code and run it."
In your example, the only code is ;
, which is the statement terminator, and so the JavaScript code does nothing.
You can also use javascript:
pseudo-protocol in bookmarks, which is how bookmarklets work.
It is an empty expression. This is often used by <a>
tags to fill href attribute and do something else in onclick
.