DEV Community

Discussion on: Checking the Dimensions of an HTML Element in Vanilla JavaScript

Collapse
zoedreams profile image
☮️✝️☪️🕉☸️✡️☯️ • Edited

nice info. The other way to access these elements is within the calculated style dimensions of the object.

w3schools.com/jsref/prop_style_hei...

function getObjHeightById(objId) {
   var obj = document.getElementById(id);
   return obj.style.height;
}
Enter fullscreen mode Exit fullscreen mode
Collapse
trusktr profile image
Joe Pea

Yet another way is with getComputedStyle(element).height/width.

Collapse
zoedreams profile image
☮️✝️☪️🕉☸️✡️☯️

Totally forgot about that one. Doesnt that one take dpi into consideration?