I\'m trying to calculate text width using jQuery. I\'m not sure what, but I am definitely doing something wrong.
So, here is the code:
var c = $(\'.c
I had trouble with solutions like @rune-kaagaard's for large amounts of text. I discovered this:
$.fn.textWidth = function() {
var width = 0;
var calc = '' + $(this).html() + '';
$('body').append(calc);
var last = $('body').find('span.textwidth:last');
if (last) {
var lastcontent = last.find('span');
width = lastcontent.width();
last.remove();
}
return width;
};
JSFiddle GitHub