JSFiddle - React, Tailwind, and code Playground
by jfriend00
HTML
<div>
<div id="test"></div>
<div></div>
</div>
<div id="result"></div>
JavaScript
function findElementPercentage(target) {
var all = document.body.getElementsByTagName("*");
for (var i = 0; i < all.length; i++) {
if (all[i] === target) {
return (i/all.length) * 100;
}
}
}
var pos = findElementPercentage(document.getElementById("test"));
document.getElementById("result").innerHTML = pos;