Here are two ways you can build a link which runs JavaScript code. Which method is more efficient in terms functionality, page loading speed, validation, and so on? Which one is better, in terms of functionality, page load speed, validation purposes etc.
function myJsFunc() {
alert("myJsFunc");
}
<a href="#" onclick="myJsFunc();">Run JavaScript Code</a>
function myJsFunc() {
alert("myJsFunc");
}
<a href="javascript:void(0)" onclick="myJsFunc();">Run JavaScript Code</a>
These are the things I use
<a href="javascript:;" onclick="myJsFunc();">Link</a>
<a href="javascript:void(0);" onclick="myJsFunc();">Link</a>
<a href="/gracefully/degrading/url/with/same/functionality.ext" class="some-selector">For great justice</a>
$(function() {
$(".some-selector").click(myJsFunc);
});
I go to the gym almost every day.
<a href="javascript:;" onclick="yourFunction()">Link description</a>
Leave a Reply