Tutorialspoint

JavaScript Example on href vs onClick

<html>
 <head>
 <title>JavaScript href vs onClick()</title>
 <script>
 function myFunc() {
 var v = 0;
 for (var j=0; j<1000; j++) {
 v+=j;
 }
 alert(v);
 }
 </script>
 <a href="javascript:myFunc()">href</a>
 <a href="#" onclick="javascript:myFunc()">onclick</a>
 </head>
 <body>
 </body>
</html>

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.