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

Alexandru Muntean
Alexandru Muntean
6,003 Points

What am I getting wrong here?

I've tried everything I know with no success.

app.js
var inputValue = document.querySelector('input#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

Peter Vann
Peter Vann
26,484 Points

Your App.js code:

var inputValue = document.querySelector('input#linkName');

is incorrect. Use this instead:

var inputValue = document.querySelector('#linkName');

Since IDs should be unique to a page, '#linkName' is all that is required.

See this example: https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_document_queryselector