If you want to use links to trigger JavaScript you can but be aware that links are supposed to be links not triggers!  If you change what they do people might get confused.  You should only really do it if the end result appears to the user to have been moving to another page.

Create a page called jslinks.html and put a function called testing inside the script element.  Inside the function add an alert saying something.  Then add this line of HTML after the h1 element:

<p><a href="javascript:testing();">Click here to run the function.</a></p>

Delete the alert and replace it with this:


Now the link acts like a link.  That is only useful if you add functionality so change the function by replacing the single line of code with this:

if(window.confirm('Are you sure?')){

Now it only goes to the page if the user confirms.