Javascript DOM CSS Style marginRight Property set

Introduction

Change the right margin of a <div> element back to "normal":

document.getElementById("myDiv").style.marginRight = "0px";

View in separate window

<!DOCTYPE html>
<html>
<head>
<style>
#myDiv {/*  ww  w  .  ja  v  a  2 s .  co m*/
  border: 1px solid #FF0000;
  margin-right: 75px;
}
</style>
</head>
<body>

<div id="myDiv">This is a div.</div>
<br>
<button type="button" onclick="myFunction()">Change right margin</button>

<script>
function myFunction() {
  document.getElementById("myDiv").style.marginRight = "0px";
}
</script>

</body>
</html>



PreviousNext

Related