Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript JavaScript and the DOM (Retiring) Making Changes to the DOM Modifying Elements

David Dehghani
David Dehghani
6,992 Points

So close I can feel it (Selecting values and storing them in variables)

I can select the element but don't know how to select the value of input. Also trailed .innerHTML and textContent at the end of the querySelector to no avail. Please help!

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>
app.js
let linkName = document.querySelector('input');

2 Answers

Damien Watson
Damien Watson
27,419 Points

To get the 'value' of an input field ;)

let linkName = document.querySelector('input').value;
David Dehghani
David Dehghani
6,992 Points

While you're around...

Set the text content of the a tag to be the value stored in the variable linkName

is the next assignment.

I did :

input.value = a.textContent;

What's confusing me is that it's asking me to store it in a variable named the same as the one from the first test. I says I can't redeclare it.

Tried a few other things but I'm not quite understanding the question.

Damien Watson
Damien Watson
27,419 Points

You need to do another query select to reference the anchor tag, then set its 'innerText' to the value from the previous challenge.

Samuel Ferree
Samuel Ferree
31,722 Points

You are close! I think you just need to add '.value'

let linkName = document.querySelector('input').value;