JavaScript Tips n Tricks: javascript:void(0)

Two options

<a href="#" onclick="myJsFunc(); return false;">Run JavaScript Code</a>

or

<a href="javascript:void(0)" onclick="myJsFunc();">Run JavaScript Code</a>

Both options do almost the same thing.  By using the second one you will not need to remember to use the “return false;” that is in the first one.  When writing large amounts of complex code using this pattern saves on bugs and time.  One issue with it is accessibility, I will need to do more research on this when the time comes.

StackOverflow question : Href attribute for JavaScript links: “#” or “javascript:void(0)”?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s