Calculating text width
jquery
Solution
This worked better for me:
$.fn.textWidth = function(){
var html_org = $(this).html();
var html_calc = '<span>' + html_org + '</span>';
$(this).html(html_calc);
var width = $(this).find('span:first').width();
$(this).html(html_org);
return width;
};
Problem
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 = $('.calltoaction'); var cTxt = c.text(); var cWidth = cTxt.outerWidth(); c.css('width' , cWidth); ```