Executing JavaScript when a link is clicked

javascript

Solution

The nice thing about onclick is you can have the link gracefully handle browsers with javascript disabled.

For example, the photo link below will work whether or not javascript is enabled in the browser:

<a href="http://www.example.com/myPhoto.jpg" target="_blank" onclick="showPhoto(this.href); return false;">foobar</a>

Problem

Which is preferable, assuming we don't care about people who don't have JavaScript enabled? ``` <a href="#" onclick="executeSomething(); return false"></a> ``` Or ``` <a href="javascript:executeSomething()"></a> ``` Is there any difference? Or there any other ways I'm missing besides attaching an event to the anchor element with a JavaScript library?

Original source

Related problems