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 Interactive Web Pages with JavaScript Selecting Elements and Adding Events with JavaScript Selecting Elements

Maurizio Galli
Maurizio Galli
23,424 Points

Why I get "Oops! It looks like Task one is no longer passing"?

This is my input...

var fullName = document.getElementById("full_name"); var lastName = document.getElementByClassName("last_name");

1 Answer

Aaron Graham
Aaron Graham
18,033 Points

It should be .getElementsByClassName. getElementById is the only DOM selector I can think of that uses a singular 'Element'. Everything else uses 'Elements'. It's a little confusing until you thing about what you might be selecting. Id's must be unique, so you are only going to get one element returned when you select it, therefore getElementById makes sense. There could be any number of elements returned when you select based on a class identifier though, so this selector uses the plural elements getElementsByClassName.

Edit: I just checked out this challenge and it might not pass using getElementsByClassName. You might need to make the selection based on the tag name and use an offset to get the correct element... just a hint...

Maurizio Galli
Maurizio Galli
23,424 Points

Thank you very much, there were 2 issues actually: as you said, the first one was about getElementsByClassName and the second one was about using getElementsByTagName. I passed the challenge :)