0

See a text width (in pixel)

In JavaScript, If I wanted to know what does a certain text take width of the line, what to do? I searched on the web, I found that I can use .cleintWidth ( https://stackoverflow.com/questions/118241/calculate-text-width-with-javascript?noredirect=1&lq=1 ) But seems it did not work for me If I writed: var t='I'; document.write(t.clientWidth); the output would be "undefined" What is the wrong? How to fix that? Or there is another method to get a text width value?

6th Apr 2022, 8:16 PM
Eyad Al-Ahmar
Eyad Al-Ahmar - avatar
2 odpowiedzi
0
FF9900 Thanks. I noticed that I should add "window.onload" to works. why exactly?
8th Apr 2022, 12:03 PM
Eyad Al-Ahmar
Eyad Al-Ahmar - avatar