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 The Event Object

Lu Favela
seal-mask
.a{fill-rule:evenodd;}techdegree
Lu Favela
Front End Web Development Techdegree Student 15,570 Points

Im a little confused about the "event.target", Versus "event.target.tagName"

Im still trying to understand the concept of event "bubbling" and "DOM traversal". I get really confused on when to use either pieces of code or how to apply it. Does "tagName" work similar to "document.elementsbyTagName"?

1 Answer

Steven Parker
Steven Parker
231,268 Points

Assuming "event" is the parameter to an event handler (the callback function of "addEventListener"), then:

  • event.target is a reference to the element that generated the event
  • event.target.tagName is the "tagName" property of that element — note that tag names are UPPER CASE

"document.getElementsByTagName()" is a function that you can use to find all the elements of a particular kind. Case is ignored so the argument should be lower case.