Javascript DOM CSS Style height Property set pixel value

Introduction

Change the height of a <div> element:

document.getElementById("myDIV").style.height = "500px";

Click the button to change the height of the DIV element:

View in separate window

<!DOCTYPE html>
<html>
<head>
<style>
#myDIV {/*from w w  w .  j a v a2  s. c om*/
  width: 100px;
  height: 100px;
  background-color: coral;
  color: white;
}
</style>
</head>
<body>
<button onclick="myFunction()">Test</button>

<div id="myDIV">
  <h1>myDIV</h1>
</div>

<script>
function myFunction() {
  document.getElementById("myDIV").style.height = "500px";
}
</script>

</body>
</html>



PreviousNext

Related