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

Can't select input

What am I doing wrong? I have tried everything shown in the prior videos (getElementById, querySelector, descendant selectors, etc)

app.js
var inputValue = document.querySelector('#inputValue');
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

Jamie Reardon
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Jamie Reardon
Treehouse Project Reviewer

Hi Seth, your argument for the querySelector method is incorrect. It is trying to collect an element with the id of inputValue. Look at the HTML markup, you can see that there isn't an element with this id name. The correct id name is linkName as shown in the input element here:

<input type="text" id="linkName">

This would be the correct value you want to pass to querySelector, also don't forget to include the # before the name value.

With just this, you would be only collecting a reference to the element itself. However, you may need to check what the task wants you to assign to the variable, if it want's the value of the element, you can do so by adding the value property at the end to complete the statement:

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

Jamie,

Thanks for your comment. In haste I incorrectly replicated the code above with that "#inputValue" ID.

I have to say - I don't recall the lesson where adding .value to to the querySelector method... I most certainly did not see that in the video that the challenge references (https://teamtreehouse.com/library/select-a-page-element-by-its-id).

In any case, I think I understand. Thank you for your time.

Jamie Reardon
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Jamie Reardon
Treehouse Project Reviewer

Hi Seth, you can see the teacher using the value property on the input element in the video you mentioned.

First you can see him logging it in the console to get the value: 4:16. Next, you can see him use it in the code at 4:49.