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

Javascript examples for CSS Style Property:left

Description

Set the left position of a <div> element:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<style>
#myDIV {//  w w  w .  j  a va2  s.c  o m
    position: absolute;
    width: 100px;
    height: 100px;
    background-color: coral;
    color: white;
}
</style>
</head>
<body>

<button onclick="myFunction()">Test</button>

<div id="myDIV">
  <h1>myDIV</h1>
</div>

<script>
function myFunction() {
    document.getElementById("myDIV").style.left = "100px";
}
</script>

</body>
</html>

Related Tutorials