Javascript DOM CSS Style right Property set

Introduction

Using negative values - Set the right position of a <div> element:

document.getElementById("myDiv").style.right = "-100px";

View in separate window

<!DOCTYPE html>
<html>
<head>
<style>
#myDiv {/*w  ww.  java2  s  . co  m*/
  border: 1px solid #FF0000;
  position: relative;
}
</style>
</head>
<body>

<div id="myDiv">This is a div element.</div>
<br>

<button type="button" onclick="myFunction()">Set right position of div to -100 px</button>

<script>
function myFunction() {
  document.getElementById("myDiv").style.right = "-100px";
}
</script>

</body>
</html>



PreviousNext

Related