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 trial
William Blair
Courses Plus Student 3,542 PointsHow do I store the text value of an anchor tag in a variable?
In the JavaScript and the DOM course we are given this DOM structure:
<!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>
And given this instuction: Set the text content of the a tag to be the value stored in the variable inputValue.
With the following JS file:
let inputValue
Here are some answers I tried and failed:
let inputValue = document.querySelector('#link').text();
let inputValue = document.getElementById('link').value;
let inputValue = document.getElementById('link').text();
let inputValue = document.getElementById('link').innerHTML;
let inputValue = document.getElementsByTagName('a')[0].innerHTML;
Daniel Abrego
2,089 Pointsalmost got it. remember that let inputValue has to have a value to pass into the innerHTML. this is how i got it, let inputValue = linkName.value; document.getElementById('link').innerHTML = inputValue;
William Blair
Courses Plus Student 3,542 PointsWilliam Blair
Courses Plus Student 3,542 PointsThe passive voice used in the instructions caused confusion for this question. I guess the course is written by programmers not grammar specialists. Dear Team Treehouse, please don't use passive voice for code challenges. When the user inputs a value, this question calls for us to redisplay that value as the link text. The question is not asking you to reassign the value of the variable "inputValue". Select the anchor tag, and assign the text value of the tag to input value and you will pass this challenge.