I am getting the error when using getElementById()
. I won't post the entire program since it's a homework assignment, but when I ment out this line of code I don't get any more syntax errors. What should I be looking for in the rest of the code that could have caused the problem?
document.getElementById("bugOne").style.left = xPos + "px";
Also- what is an "Invalid Argument" error usually caused by?
I am getting the error when using getElementById()
. I won't post the entire program since it's a homework assignment, but when I ment out this line of code I don't get any more syntax errors. What should I be looking for in the rest of the code that could have caused the problem?
document.getElementById("bugOne").style.left = xPos + "px";
Also- what is an "Invalid Argument" error usually caused by?
Share Improve this question asked Apr 8, 2013 at 23:04 user2234760user2234760 1433 gold badges5 silver badges16 bronze badges 02 Answers
Reset to default 4"Invalid Argument"
is going to be a runtime error, not a syntax error. Don't jump to getElementById()
as the culprit - you have a lot going on in one line of code. For debugging, it's useful to break up plex statements:
var bugOne = document.getElementById("bugOne");
var left = xPos + "px";
bugOne.style.left = left;
In IE8, if you set a bad value on a style property, you get an "Invalid argument"
error. I'm guessing xPos
contains either undefined
or NaN
. Set a breakpoint in your debugger and examine the value of xPos
.
Please post the the code (HTML and JS) for xPos variable and for bugOne, from definition to usage, as that might make your question easier to answer.
Also, are you using jQuery? If not, why not?
This page (linked) doesn't explain what "invalid argument" means, but it shows areas where it most likely occurs.