Which is the best way to use value for loading JavaScript link “#” or javascript:void(0)”?

Going to discuss which href value is best for load JavaScript function “#” or  javascript:void(0)”?. Here there are two methods available which you can use when user click on the link the JavaScript function execute.

1. Load JavaScript function by using “#” in href value.

<a href=”#” onclick=”yourJsFnc();”>Execute JavaScript Code</a>

2. Load JavaScript function by using “javascript:void(0)” in href value.

<a href=”javascript:void(0)” onclick=”yourJsFunc();”>Execute JavaScript Code</a>

Two reasons why you not used “#” in href value. (href=”#”) ?

1. Load function by using href=”#” and the function return some value and do something then function return task will not execute.

function doSomething() {
    //Some code
    return some-value; // not be executed
2. Another reason is that if calling function throw any exception or error the return statement is not executed. So must solved any error you may know occur during the execution of calling function.

So avoid all problems discuss in the post you should use javascript:void(0) in href value to load or execute JavaScript function.


About Moazzam Qureshi

I am SEO expert and web developer since 2011. My hobby is to write & provides quality content about blogging, SEO , Social Media , Earn Online and Affiliate Marketing.

Leave a Reply