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

Yu Ito
Yu Ito
12,711 Points

Need help.

Challenge Task 1 of 2

Store the value of the text input element in the variable inputValue. (If you need a refresher on getting the value of a text input, this video from the previous section demonstrates how.)

app.js
let inputValue = document.getElementById ("input");
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>

6 Answers

What you did is you stored the input element into the variable inputValue. The challenge wants you to store the value of the input element, this is achieved using the .value-property of your input element:

let inputValue = document.getElementById("linkName").value;

Is this also valid?:

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

I have just tried your code babasariffodeen and it returns an error. So i'd say no.

I have linked the definitions of both textContent and value definitions that may help clear things up between the two differences.

https://www.w3schools.com/jsref/prop_node_textcontent.asp ,

https://www.w3schools.com/jsref/prop_option_value.asp

Cosimo Scarpa
Cosimo Scarpa
14,047 Points

This challenge want that you store the value of the input element. So you gonna use the ID's name and use the attribute value.

let inputValue = document.getElementById("linkName").value;
Samuel Llibre-Pillco
Samuel Llibre-Pillco
15,467 Points

I know this is old but the answer is:

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

Good Luck all ;)

"linkName" is not a valid selector, your code won't know what "linkName" is. What you take as a selector is basically the same one you would use if you'd append a certain styling with css to it: In this case, you'd use the selector "#linkName", as your element has the ID of "linkName". querySelector would work if you used "#linkName" as selector.

ivana kantnerova
ivana kantnerova
15,932 Points

let inputValue = linkName.value; link.textContent = inputValue;