This solution is generated by ChatGPT, correctness is not guaranteed.

AI solution for Interview Question on BFE.dev
13. What is Event Delegation?

Sure, Event Delegation is based on the principle of event bubbling, which means that when an event triggers on a child element, it propagates up through all its parent elements until it reaches the root element of the DOM tree.

So, instead of adding event listeners to each individual child element, we can add a single event listener to its parent element using the addEventListener() method. When a child element triggers the specified event, the event propagates up to its parent element, where we can use the event.target property to determine which child element initiated the event.

This way, we can handle multiple events with a single function, which is more efficient and easier to manage. Event Delegation is especially useful when dealing with dynamic content and large amounts of elements, as we don't have to attach a listener to each one individually.