Javascript function doesnt work, simple code
<p>Quite simple code below doesnt work. No idea why, JS function to move image smoothly.
Help would be great guys, tryed almost everything. </p>

<p>Code ready to copy paste to php script and test it. 
Many thanks in advance</p>

<pre><code>&lt;?php
echo "

&lt;script type='text/javascript'&gt;

var img = document.getElementById( 'test' );

function translate( elem, x, y ) {
    var left = 120,
        top = 120,
        dx = left - x,
        dy = top - y,
        i = 1,
        count = 20,
        delay = 20;

    function loop() {
        if ( i &gt;= count ) { return; }
        i += 1;
        elem.style.left = ( left - ( dx * i / count ) ).toFixed( 0 ) + 'px';
        elem.style.top = ( top - ( dy * i / count ) ).toFixed( 0 ) + 'px';
        setTimeout( loop, delay );
    }

    loop();
}

&lt;/script&gt;
";
echo '
&lt;/head&gt;
&lt;body&gt;
  &lt;img id="test" src="http://placekitten.com/100/100" style="position:absolute; left:120px; top:120px;"&gt;


&lt;a href="#" onclick="translate(\'test\', 30 , 30)"&gt;Translate to (0, 200)&lt;/a&gt;

&lt;/body&gt;
';
?&gt;
</code></pre>
