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 trialAlisa Petrovska
4,919 PointsI need to Set the text content of the a tag to be the value stored in the variable inputValue. what is the mistake?
let inputValue = document.getElementById('linkName').value; inputValue = document.getElementById('link').textContent;
let inputValue = document.getElementById('linkName').value;
inputValue = document.getElementById('link').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>
Haowen LIU
7,381 PointsYou didn't understand the question, this question was asking you to make the value of the variable 'inputValue' as the value of the text content of the 'a' .
But the second command which you have written means that you put the value of the text content into the variable 'inputValue' . Which is on the contrary.
The correct answer is:
document.getElementById('link').textContent = inputValue;
Hope you will understand what I mean ;)
1 Answer
Adam Salima
10,998 PointsThe Problem is you are storing the value of the anchor element back into the variable inputValue. Try it the other way around and use innerHTML rather than textContent. From what I've read around the discussions innerHTML is used to manipulate texts inside an element.
Jose Agrelot
13,416 PointsJose Agrelot
13,416 PointsTry using text instead of textContext and maybe use an event view your results:
I added a button and called the changeLinkName function...