constdims = getElementDimensions('#my-element') if (dims) { console.log(dims.width, dims.height) }
// Or with a DOM element constel = document.getElementById('my-element') constdims2 = getElementDimensions(el) if (dims2) { console.log(dims2.top, dims2.left) }
Gets the dimensions and position of a DOM element or the first element matching a CSS selector.