javascript check click on element does not exist yet code example
Example 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');
}
}
Example 2: jquery for element which doesnt exist on page load
$('body').on('click', '.my_class', function(event) { ...