I have tried different ways to make an input adapt to is text. The closer I get with jQuery is: $("div").attr("size", $("div").val().length );
I think this works with the attribute size, but this does not seem to measure very well the text. It seems that size works well to measure numbers but not text:
<input type="text" id="first" name="first" size="11" value="this has 11">
<br>
<input type="text" id="second" name="second" size="11" value="12345678901">
<br>
<input type="text" id="third" name="third" size="22" value="this has 22 characters">
So, when I use size with jQuery:
$("#jQ").attr("size", $("#jQ").val().length );
HTML:
<input type="text" id="jQ" name="jQ" value="text, text, text">
Here is the example to play: http://jsfiddle.net/auk7g40m/
Is there a better way to make an input adapt to its text?