Javascript DOM CSS Style paddingTop Property set

Introduction

Change the top padding of a <div> element back to "normal":

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

View in separate window

<!DOCTYPE html>
<html>
<head>
<style>
#myDiv {/*from   w  ww.j  a v a 2s  .c  om*/
  border: 1px solid #FF0000;
  padding-top: 75px;
}
</style>
</head>
<body>

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

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

</body>
</html>



PreviousNext

Related