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

Embie Wong
Embie Wong
2,936 Points

Is there something wrong with my code?

In this challenge, I’m supposed to select the input element with the id linkName. This is what I did; is it correct? Thanks!

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

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 87,013 Points

Try using the variable to store the value of the method. So what is this means is calling .value on it like this.

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

You can also use another DOM method to get the ID like this.

var inputValue = document.querySelector('#linkName').value;
Embie Wong
Embie Wong
2,936 Points

Thanks! I tried that and it worked!