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

Jarrett Young
Jarrett Young
12,635 Points

I'm having trouble completing the code challenge in the section following this video. Can't pass the second step.

my code is as follows:

var fullName = document.getElementById("full_name"); var lastName = document.getElementsByTagName("last_name")[1];

any ideas what I'm doing wrong? any help would be greatly appreciated!!

3 Answers

Jeff Everhart
Jeff Everhart
21,732 Points

In your second variable it looks like you are using the "last_name" id or class when you should be using an HTML tag. If #last_name is a paragraph, try document.getElementsByTagName("p")[1];

Also, remember that JS uses zero indexing for most things, so if you are trying to select the first 'P' tag, you will need to use [0]. Hope that helps. If not, can you post some more specifics about what the challenge is asking?

William Li
PLUS
William Li
Courses Plus Student 26,867 Points

Hi, Jarrett, getElementsByTagName selection isn't right here, you should select the span tag.

var lastName =document.getElementsByTagName("span")[1];
Jarrett Young
Jarrett Young
12,635 Points

It worked! Yay! Jeff, you were right. I had to select the second "span" element. William, of course you were correct also, but I just happened to figure it out a few seconds before I saw your response.

Thanks so much!!