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 trialNicholas Smay
14,768 PointsMy 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
231,248 PointsThe 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.
Eden Gomez
22,565 PointsI 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
Nicholas Smay
14,768 PointsNicholas Smay
14,768 PointsThanks for clearing that up! In this situation, why do we need to but "BUTTON" in all CAPS?
Steven Parker
231,248 PointsSteven Parker
231,248 PointsEden is correct. Tag names are always stored internally in upper case.