Home Which "href" value should I use for JavaScript links, "#" or "javascript:void(0)"?
Reply: 0

Which "href" value should I use for JavaScript links, "#" or "javascript:void(0)"?

user1093
1#
user1093 Published in February 24, 2018, 9:45 pm

The following are two methods of building a link that has the sole purpose of running JavaScript code. Which is better, in terms of functionality, page load speed, validation purposes, etc.?

function myJsFunc() {
    alert("myJsFunc");
}
<a href="#" onclick="myJsFunc();">Run JavaScript Code</a>

or

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

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.760994 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO