Is there anyway to set the width of an input text type to be the width of the value inside?
CSS
input[type=text] {
width:auto;
}
JS:
$('input[type=text]').css('width', $(this).val());
Is there anyway to set the width of an input text type to be the width of the value inside?
CSS
input[type=text] {
width:auto;
}
JS:
$('input[type=text]').css('width', $(this).val());
You could use the size trick
$('input[type=text]').attr('size', function() {
return this.value.length;
});
For completeness, to make it "auto expand", you'd need an event handler as well
$('input[type=text]').on('keyup', function() {
$(this).attr('size', this.value.length);
}).trigger('keyup');
You can hack a span with the contenteditable attribute then style it to look like an input:
<span class="input" contenteditable id="input1">ddd</span>
<style>
span.input {
border: thin black solid;
padding: 2px 6px;
background-color: #EEE;
}
</style>
Given jQuery, it's easy to get that text with something like $('#input1').text();
Here's a fiddle: http://jsfiddle.net/JoeAndrieu/qYpAK/1/