Tom Knowlton
asked on
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.
javascript:void(0);
Why does it show this? And it does it for several links, each one says the same thing.
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.
ASKER
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?
no, the void is placed like so:
<a href="javascript:void(0);" onclick="DoSomething()">Cl ick 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>
<a href="javascript:void(0);"
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);"
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
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
ASKER
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);
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);
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thx
you ask to evaluate 0
void return nothing