title: Function using <a>
body: <p>I have to make the following images to switch between them when I click in the <code>&lt;a&gt;</code> link but it didn't work. When I put the 'onclick' reference in the image it works but not in the link.</p>
  
  <p>Here is the code:</p>
  
  <pre class="lang-js prettyprint-override"><code>var images=Array("1.png","2.jpg","3.png");
  var visibleImage=0;
  var a = document.getElementById("link");
  
  function change(img)
  {
      visibleImage++;
      if(visibleImage&gt;=images.length)
      {
          visibleImage=0;
      }
      img.src=images[visibleImage];
  }
  </code></pre>
  
  <p>The image look like this:</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;img src="1.png" onclick="change(this);"&gt;
  </code></pre>
  
  <p>The href link is this:</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;a href="#" onclick="change(this);"&gt;Click to change&lt;/a&gt;
  </code></pre>