My current scenario is as follows:
I have a div with a CSS property of `left:10px;`. All div elements have their positions set to fixed. I store this value in a variable using JavaScript:
var Left = document.getElementById("div").style.left;
By alerting the variable Left
, I receive a message displaying "10px". You can view this example on JSFiddle here: http://jsfiddle.net/L19rq2tk/2/
Now, my goal is to update the position value using the variable Left
. I have tried various approaches, but none seem to work:
Left = "100px"; --> does not work
Left = 100px; --> does not work
Left = "100"; --> does not work
Left = 100; --> does not work
Fortunately, I found that I can successfully change the position by directly targeting the element:
document.getElementById("div").style.left = "100px";
If anyone has any advice or solutions to this dilemma, it would be greatly appreciated!