satish123
satish123

Reputation: 541

Get Position of text inside a HTML element

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

Answers (1)

Rob M.
Rob M.

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

Related Questions