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

Christopher Evans
Christopher Evans
9,776 Points

Can't get value of input using neither getElementById nor querySelector

I followed the example of the video given and have tried all combinations of querySelector/getElementById and "input", the ID, etc etc.

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>

1 Answer

Dimitar Dimitrov
Dimitar Dimitrov
10,297 Points

you need the value of the input so .value after your selector will fix the problem.

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