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

I am confused

The error is saying that it needs to have the value of input, but does that mean the type or the id?

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>

3 Answers

Kyle Adams
Kyle Adams
10,180 Points

Your current answer:

let inputValue = document.getElementById('linkname');

Is close, but there are two problems:

  1. You must be case specific with the ID. So while linkname is not an ID in the HTML, linkName is. It's easy to overlook but will break your code!

  2. Using getElementByID( 'linkName' ); will simply find the ID tag in the document. To grab the element and find it's value, use .querySelector( '#linkName' );

Then, to find the value of that query, you can use the .value property, like this:

let inputValue = document.querySelector( '#linkName' ).value;

Hello!

Firstly, the ids are case sensitive. Therefore, document.getElementById('linkname') won't return the element with ID linkName. Secondly, inputValue should store the value of the element, not the element itself. The value of the input is the text you type inside that textbox.

Hope it helped!

How would I store the value of the element?

The element object has a property named value. There’s the value of the element.

I dont know how to do that