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

Matthew Russo
Matthew Russo
3,871 Points

Set the text content of the a tag to be the value stored in the variable inputValue.

I'm having trouble with this challenge question. I've tried the querySelector(), getElementById(), and getElementsByTagName() methods on the a tag, but nothing worked. Any ideas what I might be doing wrong?

app.js
let inputValue = document.querySelector('input').value;

inputValue = document.querySelector('#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>

2 Answers

Alexander Solberg
Alexander Solberg
14,350 Points

Rearrange your second line in app.js and see if you can figure it out :) you are very close!

Matthew Russo
Matthew Russo
3,871 Points

Thanks for the response. Nothing I've tried since yesterday has worked. Got another hint??

Alexander Solberg
Alexander Solberg
14,350 Points

Thing is that you're setting a new value for your variable, instead of using that variable to set the textContent of #link.

Try setting it up like this

document.querySelector('#link').textContent = inputValue;

This worked for me when I took the challenge :) hope it works for you too.

Adam Beer
Adam Beer
11,314 Points

Use let anchor variable on the new line and from the end delete .textContent. Now did you receive the value. On the new line use innerText. Hope this help!