Well, as you can see, the browser (in your case) adds 'px' to the style left, even if you do not. It is required to use units (in the body HTML markup as well as javascript code) anyway, to be valid with most DOCTYPEs. So use them. Otherwise, some browsers may not interpret them as pixels or (more likely) at all. This is a job for parseInt() (as long as you know you will be at all times working with positive values for the element's left position):
Code:
function left(){
var x=parseInt(document.getElementById('player').style.left);
alert(x);
document.getElementById('player').style.left=x+5+'px';
}
Or, more simply:
Code:
function left(){
document.getElementById('player').style.left=parseInt(document.getElementById('player').style.left)+5+'px';
}
Also, it is good to use more descriptive names for your functions and ones that can never be confused with words that have other predefined uses in either javascript or HTML. Since the net result of the above operation will be to move the object 5 pixels to the right, why not call the function:
moveRight()
Bookmarks