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

Yohan Aton
Yohan Aton
1,738 Points

Having trouble with task 2

Here is my code below. Task one seems correct... When I add line 2, task one becomes incorrect

  • As well, It's unclear to me how to select the second span... Any help or insight would be greatly appreciated. Thank You!

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

4 Answers

IN the second line, getElementsByTagName refers to HTML tags, ie. 'a' or 'p' for links or paragraph.
More info here : https://developer.mozilla.org/en-US/docs/Web/API/Element/getElementsByTagName

It appears you are attempting to select an element by ID or class name, as "last_name" is not a valid HTML tag.

Yohan Aton
Yohan Aton
1,738 Points

Hi mkmk, thanks for your reply. Think I'm having a brain freeze at the moment...

  • As I'm not sure what the correct valid html tag should be

Any help or insight would be greatly appreciated.

Thank you!

Hey Yohan, take a look at this page on MDN for your solution: https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementsByClassName

Yohan Aton
Yohan Aton
1,738 Points

Hi, I appreciate you chiming in but I still don't know the answer. If you'd like to share it with me so I can reverse engineer it, that would be great. Thanks!