dom event delegation Flashcards
What is the event.target?
object representing the element being the event is tied to
Why is it possible to listen for events on one element that actually happen its descendent elements?
because event flow allows for event bubbling
What DOM element property tells you what type of element it is?
.tagName
What does the element.closest() method take as its argument and what does it return?
the closest ancestor (including itself) that satisfies the selector argument
How can you remove an element from the DOM?
event.target.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?
By using event flow and choosing elements nested inside elements that you would like to include and creating if-statements to control which would activate the callback function.
You can also use capturing.
What is the affect of setting an element to display: none?
It doesn’t appear on the tree
What is the affect of setting an element to display: none?
It doesn’t appear on the tree
If you were to add another tab and view to your HTML, but you didn’t use event delegation, how would your JavaScript code be written instead?
you would have to create an event listener for a lot of different things