I used pure javascript AJAX to dynamically load content into the "test" div. However, when I try to click on a child div at index 6, an alert box is not being displayed as expected.
How can I fix the issue with the click event not working? The gets function is called once the AJAX request is complete. If I remove the event listener and replace it with directly showing an alert box, it works fine. But adding the event listener fails to bind a handler to the target div.
function gets(){
document.getElementById("test").children[6].addEventListener("click", function() {
alert(document.getElementById("test").children[6])
})
}