CSS:
<style>
#container {
width: 200px;
height: 200px;
background: green;
position: relative;
}
#box {
width: 50px;
height: 50px;
background: red;
position: absolute;
}
</style>
<div id="container">
<div id="box"> </div>
</div>
JavaScript:
var pos = 0;
var box = document.getElementById("box");
function move() {
pos += 1;
box.style.left = pos+"px"
}
If I just use box.style.left = "150px"
the red box will be right in the corner of the green box but if I use box.style.left = pos+"50px"
the same happens and I don't know why? I don't understand why even declare the variable pos in the first place.