How to get the position ((Y) top, right, bottom, (X) left) of an HTML element in JavaScript

1 Answer

0 votes
// <div id="divid">DIV</div>

const rect = divid.getBoundingClientRect();

// (Y) top, (X + width) right, (Y + height) bottom, (X) left 

console.log(rect.top, rect.right, rect.bottom, rect.left);


/*
run:

267.5
493.6999816894531
288.5
468.29998779296875

*/

 



answered Aug 14, 2024 by avibootz
edited Aug 14, 2024 by avibootz
...