Shyju Shyju - 1 year ago 68
Javascript Question

What is the Difference between onclick and href="javascript:function name?

Is there any difference between

1 : <a href="javascript:MyFunction()">Link1</a>


2 : <a href="#" onclick="MyFunction()">Link2</a>

Would one affect the page performance by any means ?

Answer Source

If your element is not actually supposed to link the user someplace, don't make it an anchor element. If you're using <a> tags just to get the underline/cursor change - don't. Use CSS on a <span> (or other element) instead. {
  text-decoration: underline;
  color: blue;
  cursor: pointer;

Keep your HTML semantic and use anchor elements only when you want to link the user somewhere.