Javascript DOM CSS Style left Property get

Introduction

Return the left position of a <div> element:

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

View 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>

<p id="demo"></p>
<script>
function myFunction() {/*from   w  w w .jav  a 2s .c o  m*/
  document.getElementById("demo").innerHTML = document.getElementById("myDiv").style.left;
}
</script>

</body>
</html>



PreviousNext

Related