I want to get a newly created HTML element that is toggling on and off after click event. Initially this does not show in the DOM when page loads.
I have several divs I am looping through, each with a link inside that I want to program to click and capture the new element while it is toggled. How do I go about doing this?
var div = document.getElementsByClassName('div'); // get divs
for ( var i =0; i < div.length; i++) { // loop through each div
var link = div[i].lastChild; // get link inside individual div
link.click(); // click link
var popup = document.getElementsByClassName('popup'); // capture new div
console.log(popup); // HTMLCollection length is 0
}
I've put the variable y into a loop and comes as undefined. This is a live / toggle DOM event, I just don't know how to go about doing this, to get that element.
Thanks