Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.
chettigari naveen1,198 Points
why not to target the UL element instead of DIV, so we can stop using IF block
please provide reason for using DIV when we have list items parent UL.
Steven Parker216,826 Points
You would still want an "if" to filter on specific elements even if the delegated handler were placed closer, since it would also get triggered by events on children of the list items.
Another good reason to apply the filter is to prevent unexpected behavior changes from future additions to the HTML.
Ivan KazakovCourses Plus Student 43,317 Points
Still adding an event listener to the
<ul> makes sense to me, even though it doesn't eliminate the necessity to check for the target. Makes less event handling in the DOM, since `
<button> aren't included in that case.