JavaScript Ninja - Element's Measurements

Posted at

(function(w){
return { 'width':{
'value': Number(w.width.toLowerCase().replace(/[^\\d\\.]/g,""))
, 'unit': w.width.replace(/[\\d\\.]/g,"")
}
,'height':{
'value': Number(w.height.toLowerCase().replace(/[^\\d\\.]/g,""))
, 'unit': w.height.replace(/[\\d\\.]/g,"")
}
}
}(
window.getComputedStyle(document.querySelector('html'))
));


get something like this:

{
width: {
value: 1092.8
, unit: "px"
}
, height: {
value: 215.2
, unit: "px"
}
}