The reason this happens is because the floating label is triggered when either the label or input element is changed. (Notice how the floating label works when the input is clicked or tabbed to).
.val() does not trigger a change event so you must accompany it with the
This Github issue describes why
.val() doesn't trigger a change event.
This Stack Overflow question is useful and provides examples of extending to something like