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.

JavaScript JavaScript and the DOM (Retiring) Responding to User Interaction Event Bubbling and Delegation

Why does Guil keep the index values?

Im unsure why Guil keeps the li index values after deleting the for loop. Wouldn't this result in an error of undefined?

2 Answers

Alex Koumparos
seal-mask
.a{fill-rule:evenodd;}techdegree
Alex Koumparos
Python Development Techdegree Student 36,861 Points

Hi Hugo,

As Guil says in the video:

there's a problem, when events fire on listDiv, how do we know which list item is triggering the event? The only thing we have is a reference to the entire div. So in the next video I'll show you how to solve that problem using what's called the event object.

So at the end of the video, the thing that will replace listitems[i], is a concept that has not been used and so needs to be explained (the event object). Guil promises that once the concept is explained, these will be replaced in the next video.

Sure enough, in the next video (The Event Object), Guil starts by explaining the event object, and then demonstrates replacing the broken code (at around 1:20) with the replacement code.

Hope that clears everything up for you.

Cheers,

Alex

Thanks Alex that clears everything up!

Guil is the best tutor.