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!

var inputValue = document.getElementById('linkName');
<!DOCTYPE html>
        <title>DOM Manipulation</title>
    <link rel="stylesheet" href="style.css" />
        <div id="content">
            <label>Link Name:</label>
            <input type="text" id="linkName">
            <a id="link" href=""></a>
        <script src="app.js"></script>

2 Answers

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