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

Dave Harrison
seal-mask
.a{fill-rule:evenodd;}techdegree
Dave Harrison
Front End Web Development Techdegree Student 7,400 Points

Making Changes to the Dom - challenge 1 first objective

I don't understand where I am going wrong with this challenge, can anyone help?

Challenge: 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.)

My Code: let inputValue = document.getElementById("linkName");

I get the error message "You have selected the element, but not gotten the value."

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

1 Answer

Hanna Mchatton
Hanna Mchatton
10,279 Points

let inputValue = document.getElementById("linkName"); does not find the value. try let inputValue = document.getElementById("linkName").value; to store the value of an input.

Additionally when the value is stored is important if you store it on page load the value will be null but if you store it on a button click the value will be whatever is in the input field.

Dave Harrison
seal-mask
.a{fill-rule:evenodd;}techdegree
Dave Harrison
Front End Web Development Techdegree Student 7,400 Points

Thanks, Brett, that works.

My problem with this is that when I ran the code for my original response in Atom and printed it out the page, it worked fine, just not on the Treehouse website challenge page. Your response adds to the code and as far as I can see wasn't referred to in the in the video re getElementById so this leaves me concerned that I am missing something somewhere.

Hanna Mchatton
Hanna Mchatton
10,279 Points

I did the code challenge and it did the trick, but yeah knowing how to use attributes in JavaScript is definitely something you'll want to get the hang of as it becomes extremely useful. So if you did miss that bit of the video I would research it more.

another helpful link: https://www.w3schools.com/jsref/prop_text_value.asp