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 trialSaurabh Yadav
825 Pointswhy can't i assign the value of a variable to the text content of another variable?
i put the value of input text into a variable inputValue by using .value function. then i selected another element a and put into a variable also called a. then i changed the textContent of a by a.textContent = inputValue;. i also tried doing inputValue.value but the first task stops working after this. how do i do it?
let inputValue = document.getElementById('linkName').value;
let a = document.getElementByTagName('a');
a.textContent = inputValue;
<!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
Jennifer Nordell
Treehouse TeacherHi there! You're so close here that I think it'd be more helpful if I give some hints. The reason you're getting the "Task 1 is no longer passing" message is because you've introduced a syntax error into your code. At this point, the code can no longer be interpreted. You've inadvertently typed getElementByTagName
instead of getElementsByTagName
. Note the plural in the latter version.
However, even if you correct that, it still won't work. I know this example only has one link, but imagine for a moment that it had 10. You would then be selecting all links on the page. Then you would have to make a loop to iterate through each link and set the value.
Hint: There's only one link on the page and it is given an ID. Try using getElementById()
instead.
Hope this helps, but let me know if you're still stuck!
Saurabh Yadav
825 Pointsthankyou very much for your time.cheers