I know how to get node coordinates using HTMLElement.offsetParent
. but how to get the text coordinates?
For example, the #t
element coordinates:
getCoords(document.getElementById('t'))
How to get the exact coordinates of the text elements question
and another
using JS?
<div style="padding: 30px 0 0 30px;">
<textarea style="width: 400px;height: 300px; line-height: 180%;" id="t">
Be specific and imagine you’re asking a question to another person.
</textarea>
</div>
let getCoords=function (node){
var x = node.offsetLeft;
var y = node.offsetTop;
var parent = node.offsetParent;
while (parent != null){
x += parent.offsetLeft;
y += parent.offsetTop;
parent = parent.offsetParent;
}
return {x: x, y: y};
}