0

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.

p.s.w.g
  • 146,324
  • 30
  • 291
  • 331
user3088126
  • 175
  • 1
  • 12

3 Answers3

3

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.

Mark Reed
  • 91,912
  • 16
  • 138
  • 175
0

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.

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
0

It is an empty expression. This is often used by <a> tags to fill href attribute and do something else in onclick.

Zaffy
  • 16,801
  • 8
  • 50
  • 77