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

Why does the tagName need to be in CAPS when using event.target.tagName?

Just out of curiosity, is there some particular reason why the tagName being referred to when using event.target.tagName must be in all capital letters (e.g., event.target.tagName == 'LI')? It doesn't seem to work if you use lowercase letters (or, at least not in the Treehouse workspace, anyway), which doesn't make a whole lot of sense to me. Is this "just the way it is," with no real rhyme or reason to it, or is there some fundamental purpose for this syntax? If I missed an explanation in the video, I apologize, but I don't recall hearing anything about it, just picking up on it in the examples the instructor typed out in the Event Object video from the JavaScript and the DOM course: https://teamtreehouse.com/library/the-event-object-2

Thank you in advance to anyone who takes the time to answer this!

4 Answers

Seth Kroger
Seth Kroger
56,414 Points

The older versions of HTML back when JavaScript was first created used all caps for tag names by convention instead of today's lowercase. To stay backwards-compatible with older code tagName() still returns all uppercase and has been stuck that way.

For some reason, the function node.tagName() (where you replace node with the node object) always returns letters in UPPERCASE. JavaScript is also case-sensitive, meaning the character "A" and the character "a" are totally different.

Tagging Guil Hernandez

I hope this helps :grin:

Happy coding! :tada:

:dizzy: ~Alex :dizzy:

Thanks, Alex!

Garrett Siegel
Garrett Siegel
7,968 Points

Seth Kroger and Alexander Davison Thanks for sharing this. I was just watching the video "The Event Object" and wondered why. Found my answer!