Add an event listener to an item that does not yet exist in vanilla javascript

advertisements

In JQuery I can do:

$(document).on("click","a.someBtn",function(e){
    console.log("hi");
});

to add an event listener to an element that doesn't exist yet. I cannot seem to figure out how to add an event listener to an element that does not exist yet in vanilla javascript.
The following does not work obviously:

query.addEventListener( "click", someListener );

Edit

What I would like to do is compare the item by query selectors. I am selecting the element that does not exist yet with querySelectorAll. It is a little more dynamic than just checking the tag name.


Use the target property in the event object to get the clicked element. Then, manually test for type/attributes/ids

document.addEventListener( "click", someListener );

function someListener(event){
    var element = event.target;
    if(element.tagName == 'A' && element.classList.contains("someBtn")){
        console.log("hi");
    }
}