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!

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

1 Answer

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