Here is what I do in my dropdownReplacement plugin :
using the detectCharWidth function, I calculate the width of the text avg char in the div, then I can multiply this by the length of the text to see if it matches the input.
at this point you can change the font for me less
here is the function:
var detectedCharWidths = {}; var detectCharWidth = function(testText){ var val = testText || "abcdef 1 2 3 4 5 6 ABCDEF ! ! %"; //correct detection depends on this more then anything if(!detectedCharWidths[val]){ var $inp = $("<span>", { "text":val, // "class":opts.selectClass, "css": {"background":"none", "margin":0, "padding":0, "overflow":"visible", "width":"auto", "color":"#FFF"} }); $body.append($inp); detectedCharWidths[val] = ($inp.width() / val.length); $inp.remove(); } return detectedCharWidths[val]; }
which should help you with this.
source share