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

Ammar Sulthan
Ammar Sulthan
3,894 Points

I don't know how to set the text content of the a tag to be the value stored in the variable inputValue.

What do you guys think is the mistake?

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


inputValue = document.textContent('#link');
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

Shay Paustovsky
Shay Paustovsky
969 Points

Hi Ammar,

You're doing a great job, but you got it confused a little bit.

In your code :

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

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

you're assigning the value of the input field immediatly to the 'inputValue' variable, and then modifying it's text content. That is where you got confused.

So let me explain :

P.S. - It's a best practice to declare variables using the "const" keyword if you're not planning to override them/change them.

const inputField = document.querySelector('.input');
const link = document.querySelector('#link')

link.textContent = inputField.value;

Here I'm selecting the input & a elements using "querySelector" method. Then I assign the textContent of the link to the value of the inputField variable.

BTW : textContent is not a method but rather a property.

Hopefully this solves your problem and confusion

Shay

I'm just an intermediate, so mark me if i am wrong, but in Ammar's statement:

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

what goes between the '(' and the ')' should be a selector such as a class or an id. I fail to see any class or id named "input", and I fail to see 'input' being preceded by see the required "." or the "#" .

And again in Shay's response, I fail to see any class called "input" that would justify the "('.input')".