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

The anchor tag's text has not been selected.

I keeping having issues with selecting things in the DOM. Would someone be kind enough to evaluate why this is not working? and refer to me a link/video of where I can improve my skills?

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

2 Answers

Adam Beer
Adam Beer
11,314 Points

In the first row, you forgot use the document.getElementById() selector.

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

"Important: In each task of this code challenge, the code you write should be added to the code from the previous task." this is the 2nd step of the challenge and the 1st line of code worked for the first step.

The 2nd line you provided, was the solution to the 2nd step, but I am still puzzled to as why my code did not pass.

Adam Beer
Adam Beer
11,314 Points

That's just a tip I think. That is based on the previous task. I do not even know why they write it out. But if you write the whole code, I don't think it's wrong.

If anyone else has stubbled upon this post, and is wondering the same thing. I recommend re-doing the DOM selection courses, and practicing the challenges multiple times. There are different methods to select elements, and it helps to do the challenges with different methods. Good luck! :)