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 parentNode to Traverse Up the DOM

Capitalisation on tagName 'BUTTON'

Hi

Is there any relevance to the tagName being upper case in this execrise? i.e. LI, BUTTON.

Thanks!

4 Answers

Umesh Ravji
Umesh Ravji
42,386 Points

Hi there Ana,

the value returned from tagName is always uppercase, so for comparison reasons your string also needs to be in uppercase.

Thanks so much for the clarification Umesh. Does this mean I should always use upper case when referencing an html element as a string? Ana

Umesh Ravji
Umesh Ravji
42,386 Points

I'm not actually sure, as I don't know if I have encountered every situation that can arise :)

In cases such as creating an element (document.createElement) or querying for elements (document.querySelectorAll), the tag is generally written in lowercase. Even though these methods also appear to work fine for uppercase too, its probably better to stick to conventions and use lowercase tags in these situations.

Great, good to know. Thanks again!

Lucas Ferrero
Lucas Ferrero
4,311 Points

consider this trick: You could use the method toLowerCase() if you want. Here an example: if(event.target.tagName.toLowerCase() === 'h1') { //do something } However it doesn't make any sence, just use H1 instead and you'll save the lower case method.