How can I set the with of '<input>'
element equal to the content with?
(The content is dynamic.)
example: http://jsfiddle.net/WG86g/
How can I set the with of '<input>'
element equal to the content with?
(The content is dynamic.)
example: http://jsfiddle.net/WG86g/
See if this works for you
<input id="chk1" type="text" onkeypress="this.style.width = ((this.value.length + 1) * 8) + 'px';">
The problem is that multiples of 8 are handled.
$("input").css("width",$(this).prop("scrollWidth"));
you should use this. simple and easy
$('#textbox').autoResize();
http://james.padolsey.com/javascript/jquery-plugin-autoresize/
EDIT:
James Padolsey left to develop this plugin. So I would recommend you to use Jack Moore's plugin. If you want to use old js file, you can access js file from here.
http://james.padolsey.com/demos/plugins/jQuery/autoresize.jquery.js/view