Javascript DOM CSS Style paddingTop Property get

Introduction

Return the top padding of a <div> element:

alert(document.getElementById("myDiv").style.paddingTop);

View in separate window

<!DOCTYPE html>
<html>
<head>
<style>
#myDiv {//from  w w  w  .j a v  a 2s  .c  o  m
  border: 1px solid #FF0000;
}
</style>
</head>
<body>

<div id="myDiv" style="padding-top:5cm;">This is a div.</div>
<br>
<button type="button" onclick="myFunction()">Return top padding</button>

<p id="demo"></p>
<script>
function myFunction() {
  document.getElementById("demo").innerHTML = document.getElementById("myDiv").style.paddingTop;
}
</script>

</body>
</html>



PreviousNext

Related