Javascript set left style doesn't work

xpos=xpos+1;
document.getElementById("img").style.left=xpos;

I can't assign xpos value to left property in javascript.

Answers:

Answer

Try adding a unit to it. Otherwise it's probably not being read by the browser due to it being invalid CSS

document.getElementById("img").style.left= xpos + "px";

You can usually figure out these kind of things by looking at the styles pane of your browser's developer tools

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us Javascript

©2020 All rights reserved.