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

Nour El-din El-helw
Nour El-din El-helw
8,241 Points

What am I doing wrong?

There is probably something wrong but I can't find it, so can someone please help?

This is the task : Set the text content of the a tag to be the value stored in the variable inputValue.

app.js
let inputValue = document.querySelector('a').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

Adam Beer
Adam Beer
11,314 Points

Select the id with getElementById() . After the getElementById() use .value and store the input value inside the inputValue variable. Hope this help.

Nour El-din El-helw
Nour El-din El-helw
8,241 Points

You probably said the right answer, same as Aakash Srivastav but I didn't get it really well because I needed some details.

Adam Beer
Adam Beer
11,314 Points

I'm sorry. We don't write the ready code, so you can't learn. We are givin guidelines. Next time I try to pay more attention for the example. Happy coding!

Nour El-din El-helw
Nour El-din El-helw
8,241 Points

Bro..It's not your problem. It's mine I usually don't get stuff except with an example or so.

Aakash Srivastav
seal-mask
.a{fill-rule:evenodd;}techdegree
Aakash Srivastav
Full Stack JavaScript Techdegree Student 11,638 Points

Hey Nour El-din El-helw , they are saying to set the textContent of the anchor element to the value of input element which gets stored in inputValue variable..
What you are doing is - getting the textContent of anchor element.
The code will be -

let inputValue = document.querySelector('#linkName').value;  // get the value of *input* element
document.querySelector('a').textContent = inputValue ;   // set the *textContent* of *a* to inputValue  

Hope it helps :)