Debugging a simple function

Hello guys,

I’m trying to attempt a simple animation, as indicated by the following code.
The intention is to move the object (a paragraph element node with id message) to the right by 200 px and down 100 px, by 1 px a second.

However, there seems to be a bug or my methodology is incomplete as the browser returns the Textvalue of the paragraph without any styling.

function moveMessage()
if (!document.getElementById) return false;
if (!document.getElementById("message")) return false;
var elem = document.getElementById("message");
var xpos = parseInt(;
var ypos= parseInt(;
if (xpos == 200 && ypos == 100)
return true;
if (xpos < 200)
if (xpos > 200) 
if (ypos < 100) 
if (ypos > 100) 
} = xpos + "px"; = ypos + "px";
movement = setTimeout("moveMessage()",10);

This makes no sense to me. How does the browser “return” something?

make sure you give the element a css position, like absolute.
make sure and top have a value. parseInt() can return NaN when it fails, and setting = “NaNpx” is not going to work well :slight_smile: