Created
January 29, 2012 14:53
-
-
Save pepebe/1699146 to your computer and use it in GitHub Desktop.
js: Calculate width of text inside a container
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've picked that one up at stack overflow. Unfortunately I can't find the source anymore.
Thanks to the unknown author.