Skip to content

Instantly share code, notes, and snippets.

@nwwells
Created September 18, 2012 21:13
Show Gist options
  • Save nwwells/3745941 to your computer and use it in GitHub Desktop.
Save nwwells/3745941 to your computer and use it in GitHub Desktop.
magically scrolling input element
var $inputEl = this.$inputEl, //get a jquery element
$tmp = $('<span />'), //create a span
$body = $('body'); // get the body
$tmp.html(_.escape($inputEl.val()));
$body.append($tmp);
var theWidth = $tmp.width();
$tmp.remove();
var widthToSet = (14 + theWidth) + 'px';
$inputEl.width(widthToSet);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment