html - Work out how many characters can fit into DIV with JavaScript -


Does anyone know how many letters can fit within the HIV block in HTML using Javascript, this is the best The way?

Any advice will be of great help.

You are not sure to check your words hidden div and its width that there is no better The way.

Edit: Something like this:

  var targetWidth = document.getElementById ('DivToCheck'). ClientWidth; Var stringToFit = 'abcdefghijk'; Var numChars = 0; (Var i = 0; i & lt; stringToFit.length; i ++) {document.getElementById ('hidden'). InnerHTML + = stringToFit.charAt (i); If (document.getElementById ('hiddenDiv'). ClientWidth & gt; targetWidth) {numChars = i - 1; break; }} And lieutenant; Div id = "hidden" style = "visibility: hidden; width: auto;" & Gt; & Lt; / Div & gt;  

Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -