dom event delegation Flashcards
What is the event.target?
the element that the event happened on
Why is it possible to listen for events on one element that actually happen its descendent elements?
thanks to event bubbling!
What DOM element property tells you what type of element it is?
event.target.tagName
What does the element.closest() method take as its argument and what does it return?
takes a CSS selector to search up the document tree for starting with itself, returns the first matching ancestor or null
How can you remove an element from the DOM?
element.remove()
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 listener to an ancestor instead