pepebe
1/29/2012 - 2:53 PM

js: Calculate width of text inside a container

js: Calculate width of text inside a container

    function textWidth(text){
     var calc = '<span style="display:none">' + text + '</span>';
     $('body').append(calc);
     var width = $('body').find('span:last').width();
     $('body').find('span:last').remove();
     return width;
    };