There is an empty popup div already loaded in the page. When the user click on an image, a div is created and sent into the popup. I'm looking for an event to listen to the end of the appendChild:
let galerieImages = document.getElementsByClassName("field-galerie-image");
let galeriePopup = document.getElementById("galerie-popup");
for(let i = 0; i < galerieImages.length; i++) {
galerieImages[i].addEventListener("click", function(e) {
e.preventDefault();
popup = document.createElement("div");
popup.innerHTML = galerieImages[i].nextElementSibling.innerHTML;
galeriePopup.appendChild(popup);
popup.addEventListener("load", function(e) {
console.log("popup loaded");
})
};
In this code, the event load doesn't seem to work with appendchild.
What kind of event is usable after an appendchild?
PS: Everything works fine until popup.addEventListener function
EDIT:
The MutationObserver function is surely the best option, but I went to the setTimeout alternative to keep my code shorter and simpler for the small function needed.
I'll learn the MutationObserver soon for future development.