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 trialYu Ito
12,711 PointsNeed help.
Challenge Task 1 of 2
Store the value of the text input element in the variable inputValue. (If you need a refresher on getting the value of a text input, this video from the previous section demonstrates how.)
let inputValue = document.getElementById ("input");
<!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>
6 Answers
ve
5,048 PointsWhat you did is you stored the input element into the variable inputValue. The challenge wants you to store the value of the input element, this is achieved using the .value-property of your input element:
let inputValue = document.getElementById("linkName").value;
Cosimo Scarpa
14,047 PointsThis challenge want that you store the value of the input element. So you gonna use the ID's name and use the attribute value.
let inputValue = document.getElementById("linkName").value;
Samuel Llibre-Pillco
15,467 PointsI know this is old but the answer is:
let inputValue = document.getElementById('linkName').value;
Good Luck all ;)
Markus Mönch
16,383 Pointssolved
ve
5,048 Points"linkName" is not a valid selector, your code won't know what "linkName" is. What you take as a selector is basically the same one you would use if you'd append a certain styling with css to it: In this case, you'd use the selector "#linkName", as your element has the ID of "linkName". querySelector would work if you used "#linkName" as selector.
Markus Mönch
16,383 Pointssolved
ivana kantnerova
15,932 Pointslet inputValue = linkName.value; link.textContent = inputValue;
babasariffodeen
6,475 Pointsbabasariffodeen
6,475 PointsIs this also valid?:
let inputValue = document.getElementById('linkName').textContent;
Charlie Harcourt
8,046 PointsCharlie Harcourt
8,046 PointsI have just tried your code babasariffodeen and it returns an error. So i'd say no.
I have linked the definitions of both textContent and value definitions that may help clear things up between the two differences.
https://www.w3schools.com/jsref/prop_node_textcontent.asp ,
https://www.w3schools.com/jsref/prop_option_value.asp