Javascript Style How to - Get client height, offset height and scroll height








Question

We would like to know how to get client height, offset height and scroll height.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
table {<!--from ww  w.jav  a 2  s  .  c  om-->
  border: 3px solid red;
}

td {
  padding: 10px;
  font-size: 30px;
}
</style>
</head>
<body>
  <table>
    <tr>
      <td>I'M A TABLE</td>
    </tr>
  </table>
    <script type='text/javascript'>
        var t = document.getElementsByTagName('table')[0];
        console.log(
            'clientHeight: ' + t.clientHeight + '\n' +
            'offsetHeight: ' + t.offsetHeight + '\n' +
            'scrollHeight: ' + t.scrollHeight   
        )
    </script>

</body>
</html>

The code above is rendered as follows: