Is there a reason that this would not work?
var xcurrent = parseInt(window.document.getElementById('firstdiv').style.left);
var ycurrent = parseInt(window.document.getElementById('firstdiv').style.top);
I’m being told it’s not an integer NaN.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Quite a few, but the likely ones are:
If element with id ‘firstdiv’ doesn’t exist,
window.document.getElementById('firstdiv')will returnnull. Attempting to access the style property ofnullwill throw an error. That’s not the result you specified though.The value returned by
.style.leftis an empty string. In that case, parseInt returnsNaNper ECMA-262.A safer approach is:
As Nathan said, you can use offsetLeft instead.