Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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,887 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.