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

I need to Set the text content of the a tag to be the value stored in the variable inputValue. what is the mistake?

let inputValue = document.getElementById('linkName').value; inputValue = document.getElementById('link').textContent;

app.js
let inputValue = document.getElementById('linkName').value;
inputValue = document.getElementById('link').textContent;
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>
Jose Agrelot
Jose Agrelot
13,416 Points

Try using text instead of textContext and maybe use an event view your results:

I added a button and called the changeLinkName function...

var linkNameInputElement = document.getElementById('linkName');
var linkNameAnchorTag    = document.getElementById('link');

function changeLinkName()
{
   linkNameAnchorTag.text = linkNameInputElement.value;
}
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
        <title>DOM Manipulation</title>
    <body>
        <div id="content">
            <label>Link Name:</label>
            <input type="text" id="linkName">
            <a id="link" href="https://teamtreehouse.com"></a>
          <button onclick="changeLinkName()">Change</button>
        </div>
        <script src="app.js"></script>
    </body>
 </html>
Haowen LIU
Haowen LIU
7,381 Points

You didn't understand the question, this question was asking you to make the value of the variable 'inputValue' as the value of the text content of the 'a' .

But the second command which you have written means that you put the value of the text content into the variable 'inputValue' . Which is on the contrary.

The correct answer is:

document.getElementById('link').textContent = inputValue;

Hope you will understand what I mean ;)

1 Answer

The Problem is you are storing the value of the anchor element back into the variable inputValue. Try it the other way around and use innerHTML rather than textContent. From what I've read around the discussions innerHTML is used to manipulate texts inside an element.