I want to add an eventListener to a div that I create dynamically. However, it does not apply to the div when I inspect it in Chrome. This is what I do:
var div = document.createElement('div');
div.addEventListener('click', function(evt) {
console.log('test');
});
var root = document.getElementById('root');
root.appendChild(inner);
Can I not add an eventListener to an element before it is added to the DOM?