<!DOCTYPE html>
<html lang="en-US">
<head>
<style>
#parent{
position:relative;
width: 400px;
height:200px;
border:1px solid red;
}
#child {
position:absolute;
width: 300px;
margin: 10px;
padding: 10px;
border:1px solid black;
}
</style>
</head>
<body>
<div id="parent">
<div id="child">
<p><b>offsetLeft</b> = margin-left (from its parent element);</p>
<p><b>offsetLeft</b> = 10;</p>
</div>
</div>
<p>Click on the button to display the offsetLeft of the child div.</p>
<button onclick="myFunction()">Click Me</button>
<p id="point"></p>
<script>
var x = document.getElementById("point");
var elem = document.getElementById("child");
function myFunction(){
x.innerHTML = "offsetLeft = " + elem.offsetLeft;
}
</script> </body>
</html>