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 One Solution

1 Answer

Hello Michal,

The getElementsByTagName() method returns a collection of all elements in the document with the specified tag name, as an HTMLCollection object.

So if you wanted to use that method over querySelector then you would have to add an [0] to the end of the the getElementsByTagName() like so:

const title = document.getElementsByTagName('h1')[0]; 
title.textContent = "Lorem Ipsum";
Michal Majewski
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Michal Majewski
Full Stack JavaScript Techdegree Graduate 18,941 Points

Thanks Juan! I also figured out this is workin:

const title = document.getElementsByTagName('h1'); for (let i = 0; i < title.length; i++) { title[i].textContent = "Lorem Ipsum"; }

But of course that is totally wet not dry solution! Cheers, and thanks one more time!