You can use the pseudo-class in which you enter the body. the state code (and also to tighten it with js with the necessary change), and in the text field itself, move the input area to the right. Instead of the vacated space, move the pseudo-class using positioning. And no js for such statics is needed.
The same implementation is used if you need a picture (phone icon) in the text field to place for styling, this is done by simple positioning and a pseudo-class. Just to stylize the information entered in the form, you probably met something like that somewhere.
In any situation, I recommend not to use js, if it is possible to implement using css.