JavaScript: onclick vs mousedown.

By Posted in - Code & JavaScript & Programming on June 22nd, 2013 javascript

Recently, I used a JavaScript onclick listener to fire off a function when an a tag was clicked. This worked great in Chrome, Firefox, and Safari. But when I tested it, though, in IE9, it failed. IE did not recognize onclick. After a bit of troubleshooting, using onmousedown turned out to be the best solution for all platforms.

Below are my observations. Hopefully, this will help someone else having this issue.

My first go:
<a onclick=”newRequestAlert();”>
Observation: Works on all browsers except IE.

So, I tried:
<a onclick=”newRequestAlert();”>
Observation: Works on IE but not other browsers (i.e., IE-specific)

Which led me to the final solution:
<a onmousedown=”newRequestAlert();”>
Observation: Eureka!!! Works everywhere.

Please leave a Comment...