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

olu adesina
olu adesina
23,007 Points

how do i store the value of a tag

need help here

app.js
let inputValue =document.querySelector('#link').value;
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

Steven Parker
Steven Parker
231,271 Points

Right method, wrong tag.

You're getting the value the right way, but you're selecting the element with an ID of "link", which is the anchor (link) element. But the instructions asked you to select the text input element instead (which has an ID of "linkName").

olu adesina
olu adesina
23,007 Points

i passed that task its asking me 'Set the text content of the a tag to be the value stored in the variable inputValue'

Steven Parker
Steven Parker
231,271 Points

Well, you know how to select that element (it was the one you had selected by mistake last time). But instead of the value property, this time you want the textContent property. Other than that, it's just swapping the sides of the assignment.

olu adesina
olu adesina
23,007 Points
let inputValue = document.querySelector('#link').textContent;

//still not getting it HELP PLEASE

Steven Parker
Steven Parker
231,271 Points

Remember what I said about "swapping the sides of the assignment":

document.querySelector('#link').textContent = inputValue;
olu adesina
olu adesina
23,007 Points

are we swapping the sides of the assignment because we are reassigning a new value to the variable? and if so would it work normally if u didn't swap

Steven Parker
Steven Parker
231,271 Points

In an assignment, the thing being assigned goes on the left side.

In task 1, you assigned the variable, so the variable name is on the left side of the equal sign.

But in task 2, you are using the value that you stored in the variable to assign the text content of the "a" element. So the variable name goes on the right side of the equal sign.