If you are just interested in growing, you can update the width
to scrollWidth
, whenever the content of the input
element changes.
document.querySelectorAll('input[type="text"]').forEach(function(node) {
node.onchange = node.oninput = function() {
node.style.width = node.scrollWidth+'px';
};
});
But this will not shrink the element.