Javascript DOM CSS Style padding Property set

Introduction

Change the padding of all four sides of a <div> element to "25px":

document.getElementById("myDiv").style.padding = "25px";

View in separate window

<!DOCTYPE html>
<html>
<head>
<style>
#myDiv {/*from w  ww  .  j ava2  s  .co  m*/
  border: 1px solid #FF0000;
  padding: 2cm 4cm 3cm 2cm;
}
</style>
</head>
<body>

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

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

</body>
</html>



PreviousNext

Related