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) Traversing the DOM Using previousElementSibling and insertBefore

My code is running fine, I just am a bit confused by a piece of code we are using.

I don't understand what exactly the event.target.tagName piece of code is doing. My program is running fine, I just want to know exactly this is doing. Thanks for any clarification you can give!

2 Answers

Steven Parker
Steven Parker
231,275 Points

The click event listener is attached to a list element that has several different elements inside it. Since events "bubble up" to parent elements, it will react to any element that is clicked inside the list.

The "event.target" is the element that was clicked, and testing the TagName for equality with "BUTTON" insures that the code in the conditional block only runs if the element that was clicked is one of the buttons.

Thanks for clearing that up! In this situation, why do we need to but "BUTTON" in all CAPS?

Steven Parker
Steven Parker
231,275 Points

Eden is correct. Tag names are always stored internally in upper case.

Eden Gomez
Eden Gomez
22,787 Points

I guess is because all the tag names are going to be stored using capital letters, not sure about that but this was what I understood