Javascript DOM CSS Style top Property get

Introduction

Return the top position of a <div> element:

alert(document.getElementById("myDiv").style.top);

View in separate window

<!DOCTYPE html>
<html>
<body>

<div id="myDiv" style="position:absolute;top:75px;">This is a div.</div>

<button type="button" onclick="myFunction()">Return top position of div</button>

<p id="demo"></p>
<script>
function myFunction() {/*  w w  w.j a va  2s.c  om*/
  document.getElementById("demo").innerHTML = document.getElementById("myDiv").style.top;
}
</script>

</body>
</html>



PreviousNext

Related