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 trialMauro Bonucci
5,953 PointsSelect the second SPAN element on the page and assign it to the variable lastName on line
Hello, in this challenge i tryed this way:
var lastName = document.getElementsByClassName("last_name")[1];
It looks it didnt work maybe because isnt the way the challenge wants to be done, but the way i did is it ok?
1 Answer
Jason Anello
Courses Plus Student 94,610 PointsHi Mauro,
That could work but there's only one element retrieved with that class name and so you would access it at index 0, not 1.
I think the challenge wants you to use getElementsByTagName
instead though. In this case, 2 span's would be retrieved and you would want the second one which is at index 1.
var fullName = document.getElementById("full_name");
var lastName = document.getElementsByTagName("span")[1];