If you are looking for the length, then you probably have a font and a rendering device in mind. I needed this once when I was positioning text on a graphic. (I wanted to position a word on the graphic so that the last letter was exactly ten pixels from the right hand side of the graphic).
I used ImageMagick for both jobs. First, you can pass it your string, font, font size (ie. 10 pt.) and attributes (italics, bold, etc), and ImageMagick will tell you how many pixels wide the string will be. (Then, in my case, I positioned the text at: $Width_Of_Graphic_In_Pixels - $Width_of_String - 10 ).
If you want something that is going to be correct no matter what browser, platform, or font the user might have, you're only going to succeed if you can ascertain the pixel width of each character in that font on that platform. Obviously, the browser knows this information (for rendering purposes) at a very low level but I doubt that that information is made available to Javascript. I wonder if you could position the text in a div or span and then query the div or span for its width? Never tried it. That's where I'd look first.