Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1733
  • Last Modified:

javascript:void(0);

Often when I hover over a link I see this in the browser link "hint" at the bottom:

javascript:void(0);


Why does it show this?  And it does it for several links, each one says the same thing.
0
Tom Knowlton
Asked:
Tom Knowlton
  • 4
  • 3
  • 3
2 Solutions
 
leakim971PluritechnicianCommented:
just mean do nothing : http://www.2ality.com/2011/05/void-operator.html

you ask to evaluate 0
void return nothing
0
 
strickddCommented:
This prevents an actual <a href="" /> from firing it's href value. That means the page won't be refreshed, redirected, etc. It forces the javascript methods (i.e. onclick) to be fired.
0
 
leakim971PluritechnicianCommented:
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Tom KnowltonWeb developerAuthor Commented:
So you can have a bunch of different links get processed in one central function and decide what to do based on the source of the click, vs hard coding the href for each link?
0
 
strickddCommented:
no, the void is placed like so:

<a href="javascript:void(0);" onclick="DoSomething()">Click Me</a>

The void(0); tells the browser to NOT evaluate the href attribute value. Instead, perform any javascript events on the link.

If you only had the following, it would do NOTHING when the link is cliked:

<a href="javascript:void(0);">Do Nothing</a>
0
 
leakim971PluritechnicianCommented:
no that's not the purpose, people use # instead javascript:void(0)

the link stay a link (mouse over effect, underline, ...) but when you click on it nothing happen
most of time you have the onclick attribute set for the link

you can use : onclick="return false;" too
0
 
Tom KnowltonWeb developerAuthor Commented:
So what might be the reason for doing this?  A practical application?

For example, when I visit an answered question on EE, at the top it has links to "share the solution" on facebook, twitter, etc. and as I hover over each button (each link) it says:

javascript:void(0);
0
 
strickddCommented:
The most common use is so that a link that goes nowhere can be center-clicked to open a new tab/page.
0
 
leakim971PluritechnicianCommented:
as you know clicking on a link redirect the user to a new page
using javascript:void(0) or # you take your link in place and add a new logic on the click
when the user click on the link you can open a CSS popup, a modal window, doing ajax operation and so on

in the other case you change the location of the current page (or reload the page if it's the same URL)
0
 
Tom KnowltonWeb developerAuthor Commented:
thx
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 4
  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now