Issue
My current code features a <button>
that, upon a single click, updates the class of a <div>
element to "fade-in" and inserts it into the DOM. This action causes the <div>
to visually fade in once it's in the DOM. However, if I click the button twice rapidly while the <div>
is already present in the DOM, the element fades out and in before being removed.
Desired Outcome
My goal is for the <div>
to fade out and be removed from the DOM with the initial click, and then fade in and be reinserted into the DOM with the second click. I want the visual effects to align with the DOM manipulation and prevent the fade-out and fade-in confusion caused by rapid clicking.
Resolution Approach
To address this issue, I have made multiple attempts with Promises, but unfortunately, none have been successful. As I am relatively new to JavaScript, I am uncertain whether my use of Promises is incorrect or if there are flaws in my overall approach. Any guidance or assistance would be greatly appreciated.