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 trialJonathan Riggs
2,589 PointsI understand the first part of the challenge with assigning the value, but how do i store the text content to the value?
I'm wondering if I'm mixing up innerHTML and textContent in this example and challenge
let inputValue = linkName.value;
inputValue = a.textContent;
<!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>
2 Answers
Steven Parker
231,269 PointsFor task 2, you need to do the opposite, store the value in the other ("a") element's text content attribute. So on the next line, the selected element and property will go on the left side of the equal sign, and "inputValue" will go on the right.
But the mechanism that makes "linkName.value" work should not be relied upon. You shoud use one of the selector methods to access the element that has that ID (perhaps "document.getElementById"?).
tomd
16,701 PointsWhat Steven said, heres one way of doing it.
They want you to use 'innerHTML' not 'textContent'
const inputValue = document.querySelector('input').value;
const link = document.querySelector('a');
link.innerHTML = inputValue;
tomd
16,701 PointsUsing the ID selector would have been a better option as its more specific
Jonathan Riggs
2,589 PointsJonathan Riggs
2,589 PointsThanks Steven. I tried using the getElementById for this one and didn't have any luck because I thought the same thing. I guess they were looking for this specific answer for the section
Steven Parker
231,269 PointsSteven Parker
231,269 PointsPerhaps you had some syntax issue. I can assure you that a correctly used selector method will pass the challenge.