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 Listening for Events with addEventListener()

Terry Babyuk
Terry Babyuk
9,231 Points

Alternative way to make list items uppercase

Hello,

For this example, instead of using:

listItems[i].textContent = listItems.textContent.toUpperCase();

is it not easier to just do:

listItems[i].style.textTransform = "uppercase";

I just find the latter a bit easier. Is there maybe an advantage of one way over the other? Thanks!

1 Answer

Sharon Hartsell
Sharon Hartsell
4,403 Points

Hello! The first code snippet listItems.textContent.toUpperCase(); actually changes the text in the markup itself from lowercase to uppercase. <li>hello world</li> becomes <li>HELLO WORLD</li>.

The second option listItems[i].style.textTransform = "uppercase"; does not change the text in the markup at all. It simply adds CSS that changes how the text shows up visually.

I usually use CSS to make text into all caps. That way, it's easier to style the text differently at various screen sizes, like using all caps on mobile devices but normal capitalization on desktop. There also seems to be some inconsistencies in how screen readers interpret all caps, where they sometimes read out all caps text in markup like an acronym instead of a word.