I can see a lot of <a href="javascript:void(0);">
on html pages. From I've read it does nothing by returning undefined
. How is this different with <href="#">
Asked
Active
Viewed 5.5k times
27

abiieez
- 3,139
- 14
- 57
- 110
-
7`#` jumps to the top of the page. – elclanrs Dec 19 '13 at 08:39
-
1#links in Modern browsers like Firefox and chrome. This causes the page to look for the available link (and jump to top if unavailable) in the page and scroll to the region. But Void does not do any action – Akshay Khandelwal Dec 19 '13 at 08:40
-
Another question related to this: How about not include href attribute in ? For example vs – Oscar Zhang Jun 20 '18 at 18:23
3 Answers
47
<a href="#">link</a>
adds # to the browser url and jumps to the top of the page.
<a href="javascript:void(0);">link</a>
simply "ignores" the link click.
<a href="#" onclick="return false;">link</a>
also ignores the href.
Don't forget that in some cases javascript might be disabled (very uncommon).

MaGnetas
- 4,918
- 4
- 32
- 52
-
Adding to that: `void 0` is essentially `undefined` - that's why browser will do nothing. – kamituel Dec 19 '13 at 08:42
-
probably something like `href="#_"` should also avoid the need for `onclick="return false;"`, which IMHO is obtrusive! – Fr0zenFyr Jul 26 '17 at 07:39
4
#
might jump to a different location in the page. Plus, it modifies the URL

Leo
- 14,625
- 2
- 37
- 55
-
modifies the url is fine but jump is not. and here if it's just "#" then the jump is to the top of the page – Akshay Khandelwal Dec 19 '13 at 08:42
-
huh? I'm confused, there's a bit of discrepancy in your comment. You say that **jump is not fine** and then that the **jump is to the top of the page**. I don't get it – Leo Dec 19 '13 at 08:49
-
which is why we use javascript:void(0) that **does not make the jump** – Akshay Khandelwal Dec 19 '13 at 08:57
-
1
4
href="javascript:void(0);
is for the case that you want it to do nothing , but still look as a link. ( blue and underline).
it's just like :javascript:return undefined;
Why ?
Because someone might do : undefined=function (){}
The #
- is an anchor which sends you to the top of the page.

Akshay Khandelwal
- 1,570
- 11
- 19

Royi Namir
- 144,742
- 138
- 468
- 792