JavaScript Tutorial/Style/top
div.style.top="100px";
<html>
<head>
<title>PrettyPretty</title>
<script type="text/javascript">
document.onclick=changeElement;
function changeElement() {
var div = document.getElementById("div1");
div.style.backgroundColor="#00f";
div.style.width="500px";
div.style.color="#fff";
div.style.height="200px";
div.style.paddingLeft="50px";
div.style.paddingTop="50px";
div.style.fontFamily="Verdana";
div.style.fontSize="2em";
div.style.border="3px dashed #ff0";
div.style.position="absolute";
div.style.left="200px";
div.style.top="100px";
div.style.textDecoration="underline";
}
</script>
</head>
<body>
<div id="div1">
This is a DIV element. Click me to see the change.
</div>
</body>
</html>
Set div position in page scroll action
<html>
<head>
<title>OnScroll Example</title>
<script type="text/javascript">
window.onscroll = function () {
var oWatermark = document.getElementById("divWatermark");
oWatermark.style.top = document.body.scrollTop;
}
</script>
</head>
<body>
<P>Try scrolling this window.</p>
<div id="divWatermark" style="position: absolute; top: 0px; right: 0px; color: #cccccc; width: 150px; height: 30px; background-color: navy">www.wbex.ru</div>
<P>Line 1</p>
<P>Line 2</p>
<P>Line 3</p>
<P>Line 4</p>
<P>Line 5</p>
<P>Line 6</p>
<P>Line 7</p>
<P>Line 8</p>
<P>Line 9</p>
<P>Line 10</p>
<P>Line 11</p>
<P>Line 12</p>
</body>
</html>