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 understand the first part of the challenge with assigning the value, but how do i store the text content to the value?

I'm wondering if I'm mixing up innerHTML and textContent in this example and challenge

app.js
let inputValue = linkName.value;
inputValue = a.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>

2 Answers

Steven Parker
Steven Parker
229,708 Points

For task 2, you need to do the opposite, store the value in the other ("a") element's text content attribute. So on the next line, the selected element and property will go on the left side of the equal sign, and "inputValue" will go on the right.

But the mechanism that makes "linkName.value" work should not be relied upon. You shoud use one of the selector methods to access the element that has that ID (perhaps "document.getElementById"?).

Thanks Steven. I tried using the getElementById for this one and didn't have any luck because I thought the same thing. I guess they were looking for this specific answer for the section

Steven Parker
Steven Parker
229,708 Points

Perhaps you had some syntax issue. I can assure you that a correctly used selector method will pass the challenge.

tomd
tomd
16,701 Points

What Steven said, heres one way of doing it.

They want you to use 'innerHTML' not 'textContent'

const inputValue = document.querySelector('input').value;
const link = document.querySelector('a'); 
link.innerHTML = inputValue;
tomd
tomd
16,701 Points

Using the ID selector would have been a better option as its more specific