Event Listener Status of Dynamically Removed/Created Element

What happens to an event listener which was attached to an element that gets dynamically removed and then dynamically recreated?  If I have a form and an event listener is attached to an element by ID (e.g. ID="f1") and then that element is removed while the even listener is attached;, will the event listener automatically go away or error? Additionally what happens if the element reappears (is recreated dynamically) after the initial attachment? This is in regards to the sequence below.

1) event listener A is attached to element with ID= "f1"
2) element "f1" is dynamically removed while event listener is attached
3) element "f1" is dynamically recreated

Thanks!
894359Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

F IgorDeveloperCommented:
Every element created in your DOM keeps their properties and events. Even if it's moved to another place in the document.

Every element removed and created again, even using the same ID and content, does not keep events attached (is another object)

See this Codepen example https://codepen.io/fraigo/pen/maMYyX

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
894359Author Commented:
Thanks!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.