Why is it bad practice to use links with the javascript: "protocol"?
- by zneak
Hello everyone,
In the 1990s, there was a fashion to put Javascript code directly into <a> href attributes, like this:
<a href="javascript:alert('Hello world!')">Press me!</a>
And then suddenly I stopped to see it. They were all replaced by things like:
<a href="#" onclick="alert('Hello world!')">Press me!</a>
For a link whose sole purpose is to trigger Javascript code, and has no real href target, why is it encouraged to use the onclick property instead of the href property?