JSFiddle - React, Tailwind, and code Playground

by Ravindra Athreya

HTML

<div id="myDiv" class="set-height">
  Content
</div>

<button onClick="myFunction()">
Set Height
</button>

CSS

.set-height {
  border: 1px solid red;
  padding: 10px;
}

JavaScript

function myFunction() {
  var div = document.getElementById("myDiv");
  var rect = div.getBoundingClientRect();
  debugger;
  x = rect.left;
  y = rect.top;
  w = rect.width;
  h = rect.height;
  alert ("Left: " + x + ", Top: " + y + ", Width: " + w + ", Height: " + h);
}