Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
テキスト ノードの境界矩形を取得する方法はありますか?
getBoundingClientRect() メソッドは要素のみで定義され、親要素は実際のテキスト ノードよりも大きくなります。
テキスト ノードを でラップし、そのスパンの を<span>取得します。boundingRect
<span>
boundingRect
var span = document.createElement('span'); textNode.parentNode.insertBefore(span, textNode); span.appendChild(textNode); var rect = span.getBoundingClientRect();