без доктайпа като тоже не алё
<style>#img2{
background: red;
height: 50px;
width: 50px;
}</style>
<button onclick='alert("Ok")'>ok</button>
<div id="img2"></div>
<script type="text/javascript" >
elemY=0;// Глобальная координата y нажатия мыши относительно элемента
drag=false;// Глобальная переменная, разрешающая или запрещающая перемещение элемента
function $$(id)
{
return document.getElementById(id);
}
$$('img2').onmousedown = function(e){
e = e || window.event;
elemY=e.clientY+document.body.scrollTop-parseInt($$('img2').style.top);
drag=true;
}
$$('img2').ondragstart = function() {return false;}
document.onmouseup = function() {drag=false; document.getElementById("img2").style.cursor = 'default'; }
document.onmousemove = function(e) {
e = e || window.event;
ely=parseInt(e.clientY)-elemY;
if(drag){
document.getElementById("img2").style.cursor = 'move';
$$('img2').style.top=e.clientY+document.body.scrollTop-elemY;
var photo_height = document.getElementById("img2");
heightImg = photo_height.height;
var Newtop = e.clientY+document.body.scrollTop-elemY;
var Newheight = heightImg;
var parentHeight = 400;
deltaBottom = parentHeight - (Newtop + Newheight);
}
}
</script>