title: How to create link on image using Javascript
body: <pre><code>&lt;div id="mydiv"&gt;
  &lt;img src="myimage.jpg" /&gt;
  &lt;/div&gt;
  &lt;script language="javascript"&gt;
  var a=document.createElement('a');
  a.href='http://mylink.com';
  document.getElementById('mydiv').appendChild(a);
  &lt;/script&gt;
  </code></pre>
  
  <p>The script doesn't work to create link on image </p>
  
  <pre><code>&lt;div id="mydiv"&gt;
      &lt;a href="http://mylink.com"&gt;&lt;img src="myimage.jpg" /&gt;&lt;/a&gt;
  &lt;/div&gt;
  </code></pre>