I have a general question about event listeners. I am trying to understand how to reattach an event listener after it has been removed due to the element re-rendering.
The project I am working on requires input fields to be hidden until a specific option is selected from a drop down menu. After the first selection, the input fields either: don’t appear if the first selection wasn’t the one to trigger the fields to appear, or the input fields won’t disappear if a different selection is made after first selecting the specific option to make them appear. The goal is to have the fields appear or disappear based on the dropdown selection.
I am listening to the dropdown for any ‘change’. I saw some stuff mentioning the use of a mutation observer but I wasn’t really understanding it.
Thought I would put this out there to see if anyone has found a solid solution or may have a better way of explaining it so I can understand what to do.
Thanks!