javascript - Clever way to predict width -


i need way predict width of string if added inside element.

the font size 16px. original idea 16px every character ended being wrong.. ideas?

you can append string body so:

function get_width_of_string() {      var div = document.createelement('div');         div.style.position = "absolute";         div.style.marginleft = "-99999px";         div.style.display = "inline-block";     div.innerhtml =  "this  string";      document.body.appendchild(div);      var width = div.offsetwidth;     document.body.removechild(div);     return width; } 

this should return width of string


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -