dom-event-delegation Flashcards
What is the event.target?
The element that was interacted with
Why is it possible to listen for events on one element that actually happen its descendent elements?
Event bubbling
What DOM element property tells you what type of element it is?
tagName property
What does the element.closest() method take as its argument and what does it return?
Takes a string of valid css selector; returns the closest ancestor element which matches the selectors (null if there is no element)
How can you remove an element from the DOM?
remove() method
If you wanted to insert new clickable DOM elements into the page using JavaScript, how could you avoid adding an event listener to every new element individually?
Add the event listener to the parent, then check that the target and tag name are the type of element you want it to react to