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 trialTheo VOGLIMACCI
8,027 PointsThe anchor tag's text content has not been set
Hello i'm confused with that last task in the challenge.
I'm selecting the whole a with querySelector and assigning it to the inputValue What's wrong? Could you explain me?
let inputValue = document.getElementById('linkName');
let aTag = document.querySelector('a');
inputValue = inputValue.value;
aTag = 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>
3 Answers
Chris Shaw
26,676 PointsHi Theo VOGLIMACCI,
To set the text or label of an anchor if you will need to be done so through either the innerHTML
or innerText
properties as currently, you're just reassigning the value of aTag
to the value of inputValue
which will be the text in the input field. Instead, what you want to be doing is taking that value and setting it using either of the aforementioned properties like I have below.
let inputValue = document.getElementById('linkName');
let aTag = document.querySelector('a');
aTag.innerText = inputValue.value;
Happy coding!
Theo VOGLIMACCI
8,027 PointsPlease can someone help me?
Theo VOGLIMACCI
8,027 PointsTheo VOGLIMACCI
8,027 PointsThanks a lot for you answer Chris. But this code won't let me validate this task 2 challenge :
Chris Shaw
26,676 PointsChris Shaw
26,676 PointsSorry the delay in getting back to you. Looking into this closer, the challenge is expecting the
.value
call to be part of theinputValue
declaration. So, instead it wants the following...The difference here is we are directly assigning the value of the input field to the
inputValue
variable and then assigning the text content of the anchor tag to that value.Happy coding!