Get the left position of a <div> element: - Javascript CSS Style Property

Javascript examples for CSS Style Property:left

Description

Get the left position of a <div> element:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<div id="myDiv" style="position:absolute;left:255px;">This is a div element.</div>

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

<script>
function myFunction() {// www  .  j ava  2s .c o m
    console.log(document.getElementById("myDiv").style.left);
}
</script>

</body>
</html>

Related Tutorials