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

1

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

// 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');
    }
}
Posted by: Guest on January-08-2021

Code answers related to "Adding an event listener to an element that doesn't exist yet"

Code answers related to "Javascript"

Browse Popular Code Answers by Language