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) 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
216,032 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
216,032 Points

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

Eden Gomez
Eden Gomez
22,565 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