+ 8
Function variables problem
Iam trying to teleport my character 1000px to the right. function keypress(loc,add){ if(add == false){ a = '++'; } else { a = '--'; } character = document.getElementById('character').style; character.loc = '1000px'; console.log(loc); }
2 Answers
+ 2
Hi Skizzles
There is no "loc" attribute in DOM Elements. So assigning a value to it wont achieve anything.
You can only really set the top and left attributes in CSS for your character.
Something like this.
var character = document.getElementById('character);
character.style.left = '1000px';
character.style.top = '100px';
Dont forget to make the item absolute/fixed positioned