views:

242

answers:

2

Hi,
Is there a way to get the bounding rect of a text node?
The getBoundingClientRect() method is defined on elements only, and the parent element is bigger then the actual text node.
10x!

A: 

This has already been sort-of answered here: http://stackoverflow.com/questions/396649/retrieving-dom-textnode-position

Reinis I.
A: 

Wrap the text node in a <span>, get the boundingRect of that span.

var span = document.createElement('span');
textNode.parentNode.insertBefore(span, textNode);
span.appendChild(textNode);
var rect = span.getBoundingClientRect();
eyelidlessness