Answer the question
In order to leave comments, you need to log in
How to find out the actual size of a text tag using Javascript?
Hello friends!
Thank you for noticing my post.
There is such a design:
<div style="width:530px; height:630px;">
<svg width="530" height="630" viewBox="0 0 530 630">
<g id="obj"><text font-family="'Open Sans'" font-size="25px" fill="rgb(0, 0, 0)">123123123</text></g>
</svg>
<div id="bRect"></div>
</div>
Answer the question
In order to leave comments, you need to log in
If I didn’t make a mistake in the syntax, then the first question can be done like this
let g = document.querySelector('#obj');
let tagText = g.firstElementChild;
let tagTextWidth = tagText.offsetWidth; // Размеры
let tagTextHeight = tagText.offsetHeight; // блока
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question