Created
October 24, 2017 12:01
-
-
Save dhavalwd/a3702d00631dfe469666c71db0857c53 to your computer and use it in GitHub Desktop.
textWidth function - calculate text width
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
// Copied from here: https://stackoverflow.com/a/2771544/1909380 | |
// jQuery function to calculate text width | |
$.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; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment