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 trialEmona Arosh
Courses Plus Student 13,007 PointsI don't know how to solve task 2 of this exercise to add the text content of the Anchor tag to the input value
I don't know how to solve task 2 of this exercise, to Set the text content of the a tag to be the value stored in the variable inputValue.
const input = document.querySelector('input');
let inputValue = input.value;
<!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>
Steven Parker
231,271 PointsJamie, that's another way to solve task 1 but the question is about task 2.
2 Answers
Steven Parker
231,271 PointsTask 2 is almost the opposite of task 1. Instead of putting a value from a form element into a variable, in task 2 you will put the value from that same variable into another element.
So the terms will be on opposite sides of the assignment, and you'll use a different selector and access a different property.
I'll bet you can get it now without an explicit spoiler.
Jamie Carter
Front End Web Development Techdegree Student 12,096 Pointsyou need to use similar methods. The key thing here is that you need to target the link.
document.getElementById('link').innerHTML = inputValue
Jamie Carter
Front End Web Development Techdegree Student 12,096 PointsJamie Carter
Front End Web Development Techdegree Student 12,096 PointsSo the aim is to set the
value
of theinput
element to the variableinputValue
First we need to locate the HTML input element using javascript.
document.getElementById('linkName')
Then we need to access the value data for the input element.
document.getElementById('linkName').value
We can do this by adding the .value to the end of the element locator.
Finally save this to the variable:
inputValue = document.getElementById('linkName').value