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

Jonathan Adams
Jonathan Adams
11,449 Points

How do I figure out how to store the value in the variable.

I watched the video in the link, and I've tried multiple approaches to solving this, but I can't figure out how to do this. Thanks in advance for any help!

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>

1 Answer

Victor Mercier
MOD
Victor Mercier
Treehouse Moderator 14,635 Points

Hi, here is how we solve the problem:

var inputValue;
//Select the input
const input = document.querySelector("#linkName")
//Assign a value to inputValue
inputValue = input.value
//Select the a element 
const a = document.querySelector("#link")
a.textContent = inputValue

If that helped you, please mark as best answer to indicate other student your issue is resolved!