calculate the height of the page js code example

Example 1: javascript get element width

var width = document.getElementById('myID').offsetWidth;//includes margin,border,padding
var height = document.getElementById('myID'). offsetHeight;//includes margin,border,padding

Example 2: how to get the height of window in javascript

//get screen height of the device by using
window.innerHeight
//get screen width of the device by using
window.innerWidth

Example 3: javascript get body height

var body = document.body,
    html = document.documentElement;

var height = Math.max( body.scrollHeight, body.offsetHeight, 
                       html.clientHeight, html.scrollHeight, html.offsetHeight );