JSFiddle - React, Tailwind, and code Playground
HTML
<div id="el1">el1</div>
<div id="el2">el2</div>
CSS
#el1 {
background: #0f0;
width: 100px; height: 100px;
position: absolute; top: 100px; left: 100px;
}
#el2 {
background: #00f;
width: 100px; height: 100px;
position: absolute; top: 150px; left: 150px;
}
JavaScript
doElsCollide = function(el1, el2) {
el1.offsetBottom = el1.offsetTop + el1.offsetHeight;
el1.offsetRight = el1.offsetLeft + el1.offsetWidth;
el2.offsetBottom = el2.offsetTop + el2.offsetHeight;
el2.offsetRight = el2.offsetLeft + el2.offsetWidth;
return !((el1.offsetBottom < el2.offsetTop) ||
(el1.offsetTop > el2.offsetBottom) ||
(el1.offsetRight < el2.offsetLeft) ||
(el1.offsetLeft > el2.offsetRight))
};
var el1 = document.getElementById('el1'),
el2 = document.getElementById('el2');
alert(doElsCollide(el1, el2));