var oDiv= document.getElementById("div"); oDiv.onmousedown= function(e){ var _this = this; var e= e || window.event; var diffX= e.clientX - _this.offsetLeft; var diffY= e.clientY - _this.offsetTop; document.onmousemove= function(e){ var e= e || window.event; _this.style.left= e.clientX -diffX + "px"; _this.style.top= e.clientY -diffY + "px"; } document.onmouseup= function(e){ this.onmousemove= null this.onmouseup= null } }