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

kris sistrunk
kris sistrunk
1,984 Points

How can I select the value of an input element?

I keep getting an error when trying to select the value of the input element. Can you help?
Here is the code:

APP.JS FILE

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

Here is the treehouse response: Bummer: You need to select the 'input' element, and store its value in the variable 'inputValue'.

Here is the INDEX.HTML FILE

<!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>

app.js
var inputValue = document.getElementById('linkName.value');
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

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

first select it, then get the value.