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

Select the second SPAN element on the page and assign it to the variable lastName on line 2. Take a look in the index.ht

Here is my complete code for both challenge questions:

var fullName = document.getElementById ("full_name"); var lastName = document.getElementByTagName("span")[1];

Not only does it tell me that is NOT Correct, its saying that the 1st code is "no longer passing".

Help Please!

2 Answers

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

Jason;

Slight syntax error, it should be getElementsByTagName() not getElementByTagName() you are missing an "s".

Happy coding;

Ken

Thank you Ken!! That was the exact problem!!

Ken Alger
Ken Alger
Treehouse Teacher

Sometimes it is the simplest things, isn't it? It can get exasperating looking for, what turns out to be, simple syntax mistakes.

Happy coding!

Jeesun Kim
Jeesun Kim
4,866 Points

Why is it wrong when I did:

```var lastName = document.getElementByClassName("last_name");

Ken Alger
Ken Alger
Treehouse Teacher

Jeesun;

The challenge asked specifically to Select the second SPAN element on the page and assign it to the variable lastName. In practice your code should work as well.

Ken