Initialize custom form component

I have a custom component that has a script for initializing the field, setting up the DOM for the field.
I want this field to be hidden by default, but I noticed it's not present in the DOM before it becomes visible.
Is there a way to either call the javascript function when it becomes visible, or have the field be present in the DOM?
Was this page helpful?