Change the left margin of a <div> element back to "normal": - Javascript CSS Style Property

Javascript examples for CSS Style Property:marginLeft

Description

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

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<style>
#myDiv {/*w w  w  .j av  a 2 s .  c om*/
    border: 1px solid #FF0000;
    margin-left: 75px;
}
</style>
</head>
<body>

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

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

</body>
</html>

Related Tutorials