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

Guadalupe Favela
Guadalupe Favela
5,986 Points

What am I missing here?

trying to call the ID. what am I doing wrong?

app.js
var 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>

2 Answers

Dmitry Polyakov
Dmitry Polyakov
4,411 Points

If you use .value you grab the text inside the input.

If you don't use .value you grab input form itself.

Dmitry Polyakov
Dmitry Polyakov
4,411 Points

Hi. You are looking to grab the value so at the end you need to use .value:

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

Guadalupe Favela
Guadalupe Favela
5,986 Points

Thanks for the clarification, but is ".value" needed go grab the Id using "document.getElementById()" every time? or only during <input> elements and forms?