Javascript examples for DOM:Element offsetWidth
Get text width with element offsetWidth
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript"> window.onload=function(){//from w w w . j av a 2s . co m var textNode = document.getElementById('text-to-measure'); var width = textNode.offsetWidth document.getElementById('answer').innerText = width } </script> </head> <body> <span id="text-to-measure">WWWWWWWWWW</span> <div id="answer"></div> </body> </html>