replied on December 19, 2022
Web forms in general do not submit/track any changes made to the HTML/CSS via JavaScript; those are purely client-side and will not be sent to the server.
When you save a draft or submit a form, it is submitting the input field data only, not the currently rendered HTML/CSS, which means any changes made via JavaScript need to be applied every time the form is loaded/rendered.
You'll need your code to be triggered as soon as the document loads so it will recreate any changes the next time you open it, but you'll also need to make some adjustments if you want the changes applied to a copy saved in the repository.
When saving a form, it uses a read-only version in which the input fields (other than checkboxes and radio buttons) are replaced by div elements, meaning .val() will not work on a read-only copy.
The easiest way to test code for that in particular is to create a User Task and set it to read only in the task configuration; this will provide a similar format to what is used in Save to Repository so you can figure out what selectors you need to use to check the values in the read-only state.