JSFiddle - React, Tailwind, and code Playground
HTML
<div id="mydiv"></div>
CSS
#mydiv {
background: #FEB100;
width: 200px;
height: 100px;
margin-left: 50px;
}
JavaScript
window.onload = function() {
// Select a div with the id 'mydiv'
var mydiv = document.getElementById('mydiv');
// Get all offsets
var offset = mydiv.getBoundingClientRect();
// Offset of the div from the right side of the viewport
var offsetRight = document.documentElement.clientWidth - offset.right;
// Offset of the div from the left side of the viewport
var offsetLeft = offset.left;
alert("Right Offset: " + offsetRight);
alert("Left Offset: " + offsetLeft);
}