Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript and the DOM (Retiring) Making Changes to the DOM Modifying Elements

Ryan Schmelter
Ryan Schmelter
9,710 Points

Can anyone please post their solution to this. I'm really stuck with what's being asked here.

Any help would be appreciated.

app.js
let inputValue = document.getElementById('linkName');
inputValue = inputValue.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

Ryan S
Ryan S
27,275 Points

Hey Ryan,

Nice work, your logic is exactly correct. But you are missing one little detail: your variable "a" needs to be declared first using let. Fix that and it will pass.

Ryan S
Ryan S
27,275 Points

Hi Ryan,

Yeah the wording on Task 2 is a little confusing. I'll try and lay it out for you so you can have another go at it.

  1. Select the <a> tag (hint: you can use the ".getElementById()" method again and store it in a variable.)
  2. Access the text content of the selected <a> tag by using the ".textContent" attribute.
  3. Update the ".textContent" attribute of the <a> tag such that it is equal to the "inputValue" from Task 1.

See if this helps you solve it. #2 and #3 can be done in one line. If you still need some help just let me know.

Ryan Schmelter
Ryan Schmelter
9,710 Points

Hey Ryan,

Thanks for your response. This was my thinking here, but I'm obviously still doing something wrong. Here's my code. Any help would be greatly appreciated.

let inputValue = document.querySelector('#linkName'); inputValue = inputValue.value; a = document.querySelector('#link'); a.textContent = inputValue;

Ryan Schmelter
Ryan Schmelter
9,710 Points

So much grief for such a stupid mistake. Thanks - I really appreciate it.

Ryan S
Ryan S
27,275 Points

No problem. Things like that are easy to miss when your mind is focused on figuring out the logic. Plus the challenge errors are sometimes a little short on information.