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 trialolu adesina
23,007 Pointshow do i store the value of a tag
need help here
let inputValue =document.querySelector('#link').value;
<!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
231,269 PointsRight 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
23,007 Pointsolu adesina
23,007 Pointsi 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
231,269 PointsSteven Parker
231,269 PointsWell, 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
23,007 Pointsolu adesina
23,007 Pointslet inputValue = document.querySelector('#link').textContent;
//still not getting it HELP PLEASE
Steven Parker
231,269 PointsSteven Parker
231,269 PointsRemember what I said about "swapping the sides of the assignment":
document.querySelector('#link').textContent = inputValue;
olu adesina
23,007 Pointsolu adesina
23,007 Pointsare 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
231,269 PointsSteven Parker
231,269 PointsIn 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.