JavaScript JavaScript and the DOM Making Changes to the DOM Modifying Elements

Carlos Gavilan
Carlos Gavilan
7,652 Points

i am confuse as to what the question is asking. i am typing document.getElementById('linkName');

document.getElementById('linkName');

app.js
var inputValue = document.querySelector("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>

2 Answers

Brandon White
seal-mask
MOD
.a{fill-rule:evenodd;}techdegree seal-36
Brandon White
Treehouse Moderator

Hi Carlos Gavilan,

Going off of the code you've provided, you're using document.querySelector() to grab the first input element in the DOM and assign the element to the variable inputValue.

What the challenge is asking you to do is to grab the input element with the id of "linkName" and store its value in the inputValue variable.

You can use document.getElementById() to do this, or you can use document.querySelector() to do this (there are additional ways you can do this as well, I'm sure). But grabbing the element is not enough, you have to all make sure that its value is assigned to the inputValue variable.

Hope this helps. Keep it up, Coder.

Daniel Jacoshenk
Daniel Jacoshenk
5,987 Points

Hi Carlos,

If you're using the .querySelector method then I believe you need to define the ID thats being select as such.

var inputValue = document.querySelector("#input");

Using the # selects an element by its ID.

However, you might notice that "input" is not actually the ID name for any element within the HTML code.

If you want to grab the element ID "linkName" and its value, I believe it can do so in one of two ways.

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

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