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 JavaScript and the DOM (Retiring) Making Changes to the DOM Modifying Elements

andres ponton
andres ponton
10,350 Points

I need help with the second task

I don't understand the second task

app.js
var inputValue=
document.
getElementById("linkName").value;
index.html
<!DOCTYPE html>
<html>
    <head>
        <title>DOM Manipulation</title>
    </head>
    <link rel="stylesheet" href="style.css" />
    <body>
        <div id="content">
            <label>Link Name:</label>
            <input type="text" id="linkName">
            <a id="link" href="https://teamtreehouse.com"></a>
        </div>
        <script src="app.js"></script>
    </body>
</html>

3 Answers

You got the last part

inputValue = anchor

backwards. Remember the browser takes the thing in the right of the equal sign, and puts it in the variable in the left side of the equal sign. You want to put the input value into the anchor text so it'd be

anchor = inputValue; 

However it doesn't accept that as the solution, it works if you remove the intermediate step when creating the "anchor " variable. This works:

var inputValue = document.getElementById("linkName").value;
document.getElementById("link").textContent = inputValue;

It's asking you to modify the text of an anchor element. You can see that right now the anchor element with the id of 'link' has no text content.

<a id="link" href="https://teamtreehouse.com">/* There's nothing here */</a>

And what should you modify it with? With the value you just stored in the variable inputValue. You can access (and set) the text content of a DOM element with the textContent property.

So you should:

  1. Select the <a> with the ID of 'link'. And assign it to a variable, maybe?
  2. Access the textContent property of that <a> element, and change it to the content of inputValue.
andres ponton
andres ponton
10,350 Points

hello this is what I did but its not right I dont know what to do

var inputValue=document.getElementById("linkName").value; var anchor=document.getElementById("link").textContent; inputValue=anchor