Return the top position of a <div> element: - Javascript CSS Style Property

Javascript examples for CSS Style Property:top

Description

Return the top position of a <div> element:

Demo Code

ResultView the demo 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>

<script>
function myFunction() {/* w w  w.  j  a  v a2s  .co  m*/
    console.log(document.getElementById("myDiv").style.top);
}
</script>

</body>
</html>

Related Tutorials