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

tried everything cant figure this out please help

chalkley is the second span element why wont this work.its say to use second span element

app.js
var fullName = full_name;
var lastName = Chalkley;
index.html
<!DOCTYPE html>
<html>
<head></head>
<body>
<h1 id="full_name"><span class="first_name">Andrew</span> <span class="last_name">Chalkley</span></h1>

<script src="app.js"></script>
</body>
</html>

3 Answers

Julian Aramburu
Julian Aramburu
11,368 Points

Hi Mark!

If you are following the lessons, in the previous one you are taught how to use a method called getElementById() , in order to use that method, you have to first select the document because that's where you wanna get the element from, and then apply the method taught in the lesson. So in order to solve this task you should set your var fullname to document.getElementById("full_name"), you would get something like this:

var fullName = document.getElementById("full_name");

Hope you find this answer useful but you should check that lesson again if some things are still unclear for you!

Keep up the good job :)!

ill try it but the first task full_name had already past.it was the second task for the last name that did not but ill try that

Abe Layee
Abe Layee
8,378 Points

In JavaScript index starts at 0. In order to select the second span, you have to use the document.getElementsByTagName() follow by a bracket [] with the number 1 inside the bracket. Let say we have three spans on the page. If we want to select the 2 span, we start at 0,1,2. Notice the 2 will be one. We humans count at 1 up but computers 0. This is how you will select the second element

var lastName = document.getElementsByTagName('span')[1];  //notice the doucment.getElementsByTagName is plural not element... this is important since is more than one span on the page.