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()

textContent

Why is the textContent on both sides of the variable?

1 Answer

I hope I am understanding your question correctly. Did you mean: "Why is the textContent on both sides of the equals sign?"? After watching the video, I believe you are referencing this line of code:

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

This function:

listItems[i].textContent.toUpperCase()

Only RETURNS the uppercase value of whatever listItems[i].textContent happens to be on that iteration. This alone:

listItems[i].textContent.toUpperCase()

does not change listItems[i].textContent itself. The only way to achieve a persisting modification of the listItems[i].textContent text is to reassign the modified textContent back to itself, which is what this line of code it doing:

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

Is that what you meant? Anyway, I hope that helps. Happy coding!