Skip to content

Instantly share code, notes, and snippets.

@pepebe
Created January 29, 2012 14:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pepebe/1699146 to your computer and use it in GitHub Desktop.
Save pepebe/1699146 to your computer and use it in GitHub Desktop.
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;
};
@pepebe
Copy link
Author

pepebe commented Jan 29, 2012

I've picked that one up at stack overflow. Unfortunately I can't find the source anymore.

Thanks to the unknown author.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment