Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Determine the dimensions of the window or elements
function element_WH(elem){
var res={};
if(elem==undefined){
res.width = window.innerWidth || html.clientWidth || body.clientWidth || screen.availWidth;
res.height = window.innerHeight || html.clientHeight || body.clientHeight || screen.availHeight;
}else{
var display=elem.style.display;
elem.style.display="block";
res.width = elem.innerWidth || elem.clientWidth;
res.height = elem.innerHeight || elem.clientHeight ;
elem.style.display=display;
}
return res;
};
element_WH(document.getElementById("someId")); //return JSON, element width and height
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment