home ~ projects ~ socials

Get The Width And Height Of An HTML Element In JavaScript

// TODO: turn this into an example

/*
loadParent() {
  // console.log('Loading parent');
  const el = this.parentElement;
  const bounds = el.getBoundingClientRect();
  console.log(el);
  // console.log(el.width);
  this.parent = {
    //'width': parseInt(el.width.replace('px', '')),
    //'height': parseInt(el.height.replace('px', '')),
    'width': Math.floor(bounds.width),
    'height': Math.floor(bounds.height),
  }
  if (el.style.paddingLeft) {
    this.parent.width -= this.convertToPixels(el.style.paddingLeft);
  }
  if (el.style.paddingRight) {
    this.parent.width -= this.convertToPixels(el.style.paddingRight);
  }
  if (el.style.paddingTop) {
    this.parent.height -= this.convertToPixels(el.style.paddingTop);
  }
  if (el.style.paddingBottom) {
    this.parent.height -= this.convertToPixels(el.style.paddingBottom);
  }
}
*/
-- end of line --