When an input element is rendered, it should have a width of 0. However, when there is no text in the input, the width should remain 0.
To achieve this, you can use the following jQuery code:
$('input').on('input', function () {
$(this).attr('size', $(this).val().length);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="text" size="0">
The size
attribute works correctly for all sizes greater than 0, but for a size of 0, the browser defaults to a standard width instead of rendering it as a width of 0.
Is there a way to make an input element with a size attribute of 0 render as having a width of 0 in the browser?