title: a.getAttribute("href") returns img src instead of a href
body: <p>We've got a problem here: This small script should edit the href attribute of links if the href doesn't contain particutlar domains. Unfortunately when an <code>&lt;a&gt;</code> element contains an <code>&lt;img&gt;</code>, the JS will look for the image's <code>src</code> attribute, instead of the a's <code>href</code>.
  Why is that? I just use getAttribute("href") on an <code>&lt;a&gt;</code>, not on an <code>&lt;img&gt;</code>?</p>
  
  <p>It works if the <code>&lt;a&gt;</code> element does contain normal text instead of an <code>&lt;img&gt;</code>.</p>
  
  <p>This is the JS:</p>
  
  <pre><code>var domains = ["mysite.com", "mysite2.com"];
  var elements = document.getElementsByTagName("a");
  for (var i = 0; i &lt; elements.length ; i++)
  {
      var notFound = 0;
      for (var k = 0; k &lt; domains.length; k++) //iterate over all domains defined by user
      {
          var found = false;
          (elements[i].getAttribute("href").search(domains[k]) != -1) ? found = true : found = false; 
          if (!found) //not found
          {
              notFound++;
          }
      }
      if (notFound == domains.length) //link is outbound:
      {
          //Set link with outbound tracking parameter
      }
  }
  </code></pre>
  
  <p>This is the HTML:</p>
  
  <pre><code>&lt;a href="http://facebook.com/38293729"&gt;
      &lt;img width="100%" height="100%" src="http://mysite.com/images/fb_button.png"&gt;&lt;/img&gt;
  &lt;/a&gt;
  </code></pre>
  
  <p>Can someone explain this behaviour and provide us with a tipp or a solution?
  Thanks in advance</p>
  
  <p>Jan</p>