Change the padding of all four sides of a <div> element to "25px": - Javascript CSS Style Property

Javascript examples for CSS Style Property:padding

Description

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

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<style>
#myDiv {//from   ww w . j  av a2  s . com
    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>

Related Tutorials