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 trialashique desai
3,662 PointsSet the text content of the a tag to be the value stored in the variable linkName.
Hi there, I have tried to solve this using various methods but still could not find the right solution. There is a similar question on the forum but that too is not answered satisfactorily. Can any body help me with this challenge?
<!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>
```JavaScript
let linkName = document.getElementById('linkName').value.textContent('a');
2 Answers
Eduardo Parra San Jose
12,579 PointsHi,
I'll try to help. I think the issue is you're trying to do everything in one single step, but there are two steps to accomplish in the challenge. The first one you store the value of the input:
let linkName = document.getElementById("linkName").value;
And the second one, you have to set the text of the a tag to the value stored in the linkName variable:
// link is the id of the a tag
document.getElementById("link").textContent = linkName;
To make changes in an element you must select it first, in your code you just select the input element with the id of linkName, but then you have to select the anchor element with the id of link to make changes in the a tag. In the challenge, you cannot do both things at once ;)
I hope you find it useful. Have a nice day
Justin Oakerson
1,758 PointsI was stuck as I didn't know textContent existed...:((
ashique desai
3,662 Pointsashique desai
3,662 PointsThanks a lot, Eduardo Parra.
Vernon Neilly
2,652 PointsVernon Neilly
2,652 PointsI am also stuck on this question:
Here is what is in my app.js file:
const myInput = document.querySelector('input'); let inputValue = myInput.value; const myAnchor = document.querySelector('a#link'); inputValue = myAnchor.textContent;
Here are the two differences that I see in my code.
Where did I go wrong?
Thanks in advance,
VN2.
Amed Alberto Sanchez
Python Development Techdegree Student 2,879 PointsAmed Alberto Sanchez
Python Development Techdegree Student 2,879 PointsThe challegenge has now been updated. Eduardo Parra San Jose answer is correct, just change linkname with inputValue.
William Keith
17,827 PointsWilliam Keith
17,827 PointsThanks Eduardo Parra,