Javascript DOM CSS Style padding Property get

Introduction

Return the padding of a <div> element:

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

View in separate window

<!DOCTYPE html>
<html>
<head>
<style>
#myDiv {// ww w.ja va  2 s.co m
  border: 1px solid #FF0000;
}
</style>
</head>
<body>

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

<p id="demo"></p>


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

</body>
</html>



PreviousNext

Related