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

Theo VOGLIMACCI
Theo VOGLIMACCI
8,027 Points

The anchor tag's text content has not been set

Hello i'm confused with that last task in the challenge.

I'm selecting the whole a with querySelector and assigning it to the inputValue What's wrong? Could you explain me?

app.js
let inputValue = document.getElementById('linkName');
let aTag = document.querySelector('a');

inputValue = inputValue.value;
aTag = inputValue;
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

Chris Shaw
Chris Shaw
26,676 Points

Hi Theo VOGLIMACCI,

To set the text or label of an anchor if you will need to be done so through either the innerHTML or innerText properties as currently, you're just reassigning the value of aTag to the value of inputValue which will be the text in the input field. Instead, what you want to be doing is taking that value and setting it using either of the aforementioned properties like I have below.

let inputValue = document.getElementById('linkName');
let aTag = document.querySelector('a');

aTag.innerText = inputValue.value;

Happy coding!

Theo VOGLIMACCI
Theo VOGLIMACCI
8,027 Points

Thanks a lot for you answer Chris. But this code won't let me validate this task 2 challenge :

let inputValue = document.getElementById('linkName');
let aTag = document.querySelector('a');

inputValue = inputValue;
aTag.innerText = inputValue.value;
Chris Shaw
Chris Shaw
26,676 Points

Sorry the delay in getting back to you. Looking into this closer, the challenge is expecting the .value call to be part of the inputValue declaration. So, instead it wants the following...

let inputValue = document.getElementById('linkName').value;
let aTag = document.querySelector('a');

aTag.innerText = inputValue;

The difference here is we are directly assigning the value of the input field to the inputValue variable and then assigning the text content of the anchor tag to that value.

Happy coding!

Theo VOGLIMACCI
Theo VOGLIMACCI
8,027 Points

Please can someone help me?