Last active
April 27, 2016 18:17
-
-
Save shaneparsons/68b15108adbf3216e2f36030c1e7d804 to your computer and use it in GitHub Desktop.
jQuery - Calculate height of text from DOM element or string.
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
$.fn.textHeight = function (text, font, transform) { | |
if (!$.fn.textWidth.fakeEl) $.fn.textWidth.fakeEl = $('<span>').hide().appendTo(document.body); | |
$.fn.textWidth.fakeEl.text(text || this.val() || this.text()) | |
.css('font', font || this.css('font')) | |
.css('text-transform', transform || this.css('text-transform')); | |
return $.fn.textWidth.fakeEl.height(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment