x.innerHTML += document.body.appendChild(x); x.style.width="100px";
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
var position=0;
function deplacement(){
position=position+20;
var mon_element=document.getElementById("element_a_deplacer");
mon_element.style.marginLeft=position+'px';
if(position<=300){
setTimeout(deplacement,50);
}
}
</script>
</head>
<body>
<div id="element_a_deplacer" style='margin-left:0px;height:30px;width:30px;background:red;'></div>
<br>
<button onclick='deplacement()'>teste</button>
</body>
</html>