Return the top padding of a <div> element: - Javascript CSS Style Property

Javascript examples for CSS Style Property:paddingTop

Description

Return the top padding of a <div> element:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<style>
#myDiv {// w  w  w.  j  av a  2 s. 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>

<script>
function myFunction() {
    console.log(document.getElementById("myDiv").style.paddingTop);
}
</script>

</body>
</html>

Related Tutorials