I have to use this js code to add an array by taking values from buttons that have been clicked. So, I stored them in an array to pass it in the function which will add to my main HTML. The problem I am facing is that it gets added into the array by each button I clicked but it will not give time for each element to execute. It directly shows the last element effect.
// We create a Promise and return it
new Promise((resolve, reject) => {
const animationName = `${animation}`;
const node = document.querySelector(element);
node.classList.add(`${prefix}animated`, animationName);
// When the animation ends, we clean the classes and resolve the Promise
function handleAnimationEnd(event) {
event.stopPropagation();
node.classList.remove(`${prefix}animated`, animationName);
resolve("Animation ended");
}
node.addEventListener("animationend", handleAnimationEnd, { once: true });
});
var arrayOfButtonId = [];
var counter = 1;
$(".buttons-container").click(function (e) {
var clickedItemId = e.target.id;
// var clickedItemValue = e.target.value;
arrayOfButtonId.push(clickedItemId);
arrayOfButtonId.forEach((index) => {
console.log(index);
animateCSS(".sample-display", index).then(() => {
alert(" animation created successfully!");
});
});
});
This is the code I tried to implement .