Adding an event listener to an element that doesn't exist yet
snippet in javascript

Adding an event listener to an element that doesn't exist yet

user6026

// You need to add the event listener when the element is created.
function createEventListener() {
  	var node = document.createElement('div');
    if (node) {
        node.addEventListener('click', function() {
            console.log('Clicked Node');
        });
    } else {
            console.error('No node');
    }
}