What is the difference between the different methods of putting JavaScript code in an ?

I quite enjoy Matt Kruse’s Javascript Best Practices article. In it, he states that using the href section to execute JavaScript code is a bad idea. Even though you have stated that your users must have JavaScript enabled, there’s no reason you can’t have a simple HTML page that all your JavaScript links can point to for their href section in the event that someone happens to turn off JavaScript after logging in. I would highly encourage you to still allow this fallback mechanism. Something like this will adhere to “best practices” and accomplish your goal:

<a href="javascript_required.html" onclick="doSomething(); return false;">go</a>

Leave a Comment