JS Image change won't work under other tags (should be a simple fix)
<p>Hey guys,
basically this is my page and the JS simply changes the images if one is clicked, this works grand if the  <code>&lt;a href="#1" onclick="worseChange()"&gt; &lt;img src='worseun.png' name='worse' border='0' /&gt; &lt;/a&gt;</code> is first beneath the <code>&lt;body&gt;</code>, but doesn't work if there is another <code>&lt;img src='' /&gt;</code> above it! I'm still learning js and this is a head wreck, can anyone suggest a fix? Heres it working with nothing above</p>

<pre><code> &lt;script type="text/javascript"&gt;
    function worseChange()
    {
    var theImga = document.getElementsByTagName('img')[0].src;

    var xa = theImga.split("/");
    var ta = xa.length-1;
    var ya = xa[ta];


    if(ya=='worseun.png')
    {
    document.images.worse.src='worse.png';
    document.images.cd.src='cdun.png';
    }
    }

    function cdChange()
    {
    var theImgb = document.getElementsByTagName('img')[1].src;

    var xb = theImgb.split("/");
    var tb = xb.length-1;
    var yb = xb[tb];


    if(yb=='cdun.png')
    {
    document.images.worse.src='worseun.png';
    document.images.cd.src='cd.png';
    }
    }

    &lt;/script&gt;



    &lt;/head&gt;
    &lt;body&gt;
    &lt;a name=1&gt;Uno&lt;/a&gt;
    &lt;a href="#1" onclick="worseChange()"&gt; &lt;img src='worseun.png' name='worse' border='0' /&gt; &lt;/a&gt;&lt;br /&gt;
    &lt;a href="#2" onclick="cdChange()"&gt; &lt;img src='cd.png' name='cd' border='0' /&gt; &lt;/a&gt;
    &lt;a name=2&gt;Dos&lt;/a&gt;
    &lt;body&gt;
</code></pre>

<p>Thanks guys,
James</p>
