title: Dynamically Insert Links Inside Span Tag Using Javascript
body: <p>I have this: </p>
  
  <pre><code>&lt;span class="image"&gt;&lt;img src="something.jpg"&gt;&lt;/span&gt;
  </code></pre>
  
  <p>I want to transform it to that using javascript: </p>
  
  <pre><code>&lt;span class="image"&gt;&lt;a href="domain"&gt;&lt;img src="something.jpg"&gt;&lt;/a&gt;&lt;/span&gt;
  </code></pre>
  
  <p>It has to be done using javascript in order to hide the affiliate links.</p>
  
  <p>I have tried this script but it seems not to work:</p>
  
  <pre><code>function changespan() {
  find all &lt;span&gt; tags;
  for each &lt;span&gt; with class="image"{
  URL = "http://domain.com"
  Create new link to URL;
  insert link into &lt;span&gt;;
  }       
  }
  </code></pre>
  
  <p>The function is uploaded in file script.js and I load it in this fashion:             </p>
  
  <pre><code>&lt;script type="text/javascript" src="script.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript"&gt;
  window.onload = changespan;
  &lt;/script&gt;
  </code></pre>
  
  <p>EDIT: After this is solved, how could i parse my page to find links in this format:
   and then assign this value to variable URL. I need to be able to assign first path to URL_1 second to URL_2 and so on. </p>