Created
August 24, 2012 15:39
-
-
Save lkptrzk/3452103 to your computer and use it in GitHub Desktop.
Use number of characters to set textbox width
This file contains hidden or 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 setWidthInChars(selector, numChars) { | |
| $('body').append('<div id="testwidth"><span> </span></div>'); | |
| var w = $('#testwidth span').width(); | |
| alert(w); | |
| $('#testwidth').remove(); | |
| $(selector).css('width', (w * numChars + 1) + 'px'); /* +1 is for rounding problems */ | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment