Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript and the DOM (Retiring) Responding to User Interaction Listening for Events with addEventListener()

Terry Babyuk
Terry Babyuk
9,212 Points

Alternative way to make list items uppercase


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,402 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.