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 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,868 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!!