Skip to content

Instantly share code, notes, and snippets.

@AMHOL
Created November 7, 2013 16:34
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 AMHOL/7357563 to your computer and use it in GitHub Desktop.
Save AMHOL/7357563 to your computer and use it in GitHub Desktop.
(function(window, $, undefined) {
'use strict';
$.fn.textWidth = function() {
var $span = $('<span />', {
text: $(this).text() || $(this).val()
}).css({
margin: 0,
padding: 0,
width: 'auto',
font: $(this).css('font'),
display: 'inline',
visibility: 'hidden'
}).appendTo(document.body);
var width = $span.width();
$span.remove();
return width;
};
})(this, jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment