Reputation: 541
I am trying to detect the position of text inside a HTML element (assume, <div>
tag) (top, left, bottom and right coordinates) on the screen. I have tried offsetLeft, and offsetWidth. But, it doesn't help. Please help.
Thanks.
Upvotes: 2
Views: 2755
Reputation: 36511
You were on the right track, not sure where you got lost but you can determine coordinates using the following:
Top: node.offsetTop
Left: node.offsetLeft
Bottom: (node.offsetTop + node.offsetHeight)
Right: (node.offsetLeft + node.offsetWidth)
https://jsfiddle.net/p56xgpmb/
Upvotes: 2