Could someone please explain what I'm doing wrong here. I'm trying to move a division to a specific distance from the top plus the height of another division.
This moves the div far more than 50 pixels.
Thanks for your help.
<html>
<head>
<title></title>
<style>
#myDiv, #MoveThis
{border-style: solid; padding: 10px; position: absolute;}
#myDiv
{top: 50px;
left: 0px}
#MoveThis
{top: 150px;
left: 0px}
</style>
<script>
function AddHeight(id,pixels) {
var DivHeight = document.getElementById('myDiv').offsetHeight;
document.getElementById(id).style.top = DivHeight+pixels;
}
</script>
</head>
<body>
<a href="#" onClick="AddHeight('MoveThis','50')">Move it</a>
<div id="myDiv">
content<br>
content<br>
content<br>
content
</div>
<div id="MoveThis">
content<br>
content<br>
content<br>
content
</div>
</body>
</html>
This moves the div far more than 50 pixels.
Thanks for your help.
<html>
<head>
<title></title>
<style>
#myDiv, #MoveThis
{border-style: solid; padding: 10px; position: absolute;}
#myDiv
{top: 50px;
left: 0px}
#MoveThis
{top: 150px;
left: 0px}
</style>
<script>
function AddHeight(id,pixels) {
var DivHeight = document.getElementById('myDiv').offsetHeight;
document.getElementById(id).style.top = DivHeight+pixels;
}
</script>
</head>
<body>
<a href="#" onClick="AddHeight('MoveThis','50')">Move it</a>
<div id="myDiv">
content<br>
content<br>
content<br>
content
</div>
<div id="MoveThis">
content<br>
content<br>
content<br>
content
</div>
</body>
</html>
Comment