- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
JavaScript function in href vs. onClick
Both onclick & href have different behaviors when calling JavaScript directly. Also the script in href won’t get executed if the time difference is short. This is for the time between two clicks.
Example
Here’s an example showing the usage of href vs onClick in JavaScript.
<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>
- Related Articles
- jQuery.click() vs onClick
- Call a function with onclick() – JavaScript?
- Function Expression vs Function Declaration in JavaScript?
- How to call a JavaScript function from an onClick event?
- What is onclick event in JavaScript?
- JavaScript - Get href value
- What is onclick not working for two or more links for same function in JavaScript?
- How to call multiple JavaScript functions in onclick event?
- d vs D in JavaScript?
- Window.onload vs onDocumentReady in javascript
- Push() vs unshift() in JavaScript?
- Undeclared vs Undefined? In JavaScript
- innerHTML vs innerText in JavaScript.
- Arrays vs Set in JavaScript.
- Const vs Let in JavaScript.

Advertisements