troubleshooting Question

Why use javascript.void()?

Avatar of Bruce Gust
Bruce GustFlag for United States of America asked on
2 Comments1 Solution38 ViewsLast Modified:
What does "javascript.void()" mean?

If I'm triggering a JS function with a link, I would normally write it like this:

<a href="#" id="doSomething">hit me</a>

And then my code would be something comparable to this:

$('#doSomething').onclick(function() {
    something powerful

I'm working on some code that has this:

<a href="javascript:void(0);" class="open-company-details" data-company-id="5e7c9a662bfed251b4281e51" data-route="companies">Loose Cannon Fitness</a>

When I go out to resources such as this:, I get this definition:

If inserting an expression into a web page results in an unwanted effect, then use JavaScript void to remove it. Adding “javaScript:void(0)”, returns the undefined primitive value.

It SOUNDS like it's doing something like "#," but maybe a little more?

What does it mean and why would I want to use it as opposed to "#?" I'm thinking the bottom line is to tell the system to basically ignore the normal protocol. "I'm telling my link, Yes,you're normally a link, but, in this instance you're triggering some JS." That's what I'm doing with the "#" character, yes?

So, why javascript.void()?
Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros