@CSDevAr @Kathy_Darling “Event bubbling” is the keyword you’re looking for. See javascript.info/bubbling-and-cap…
@Kathy_Darling You would attach the event listener to a parent element and listen for the target that matches the selector instead. If the target of the event matches your selector, then do whatever action you need to do.
@Kathy_Darling I’m guessing you want to have an event listener listen for events that happen to elements that get added after the event listener is set up. For that you can use event bubbling.
@Kathy_Darling querySelectorAll() will match the selector against the current DOM when it is called. If you call querySelectorAll() after a new element is added to the DOM, it will be selected automatically.
@Kathy_Darling The spam bots