The first is a link using the javascript
protocol to tell the browser to execute everything after that as JavaScript, rather than trying to load the resource that it points to.
On the other hand, the onclick
attribute is an actual JavaScript event handler, and shouldn't be used with javascript:
at the beginning - it already knows that it's JavaScript so doesn't need to be told to execute it as JavaScript.
However, in the interests of separating out your content (HTML) and functionality (JavaScript), it's better to use neither of the above techniques, and instead add (for example) id
attributes to identify your elements and then use JavaScript to bind your event handlers.
HTML:
<a href="#" id="test-anchor">test</a>
JavaScript:
document.getElementById('test-anchor').onclick = function(event) {
jsFunction();
}