I have to make the following images to switch between them when I click in the `<a>` link but it didn't work. When I put the 'onclick' reference in the image it works but not in the link.

Here is the code:

```js
var images=Array("1.png","2.jpg","3.png");
var visibleImage=0;
var a = document.getElementById("link");

function change(img)
{
    visibleImage++;
    if(visibleImage>=images.length)
    {
        visibleImage=0;
    }
    img.src=images[visibleImage];
}

```

The image look like this:

```html
<img src="1.png" onclick="change(this);">

```

The href link is this:

```html
<a href="#" onclick="change(this);">Click to change</a>

```