0

Is it possible to get bounding rect of specific text fragment inside text node?

Say I have this HTML <p> Word1 word2 word3 word4 </p>

and I'd like to know bounding rect of word3.

1 Answers1

1

Not directly, but you could span the word and get that span bounding box.

miguel-svq
  • 2,136
  • 9
  • 11
  • Thanks, I did this, but I have very long text nodes (part of books), and I need to be able to address any word. When I surround every word with span it took a while to load, so I am looking for faster solution. – Aleksandr Nikiforov May 29 '14 at 12:10
  • Have you try doing it "on the fly" just for the desired word?. 1.- Add the spans with unique ids (_myspan_number). 2.- read the boxes. 3.- remove spans (you have the ids). Even in a quite long text this could be very fast without too much DOM manipulation. – miguel-svq May 29 '14 at 12:19
  • Ok, I did some variation of this, so I marked your answer as correct. – Aleksandr Nikiforov Jun 04 '14 at 10:02