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 trialDavid Dehghani
6,992 PointsSo close I can feel it (Selecting values and storing them in variables)
I can select the element but don't know how to select the value of input. Also trailed .innerHTML and textContent at the end of the querySelector to no avail. Please help!
<!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>
let linkName = document.querySelector('input');
2 Answers
Damien Watson
27,419 PointsTo get the 'value' of an input field ;)
let linkName = document.querySelector('input').value;
Samuel Ferree
31,722 PointsYou are close! I think you just need to add '.value'
let linkName = document.querySelector('input').value;
David Dehghani
6,992 PointsDavid Dehghani
6,992 PointsWhile you're around...
Set the text content of the a tag to be the value stored in the variable linkName
is the next assignment.
I did :
input.value = a.textContent;
What's confusing me is that it's asking me to store it in a variable named the same as the one from the first test. I says I can't redeclare it.
Tried a few other things but I'm not quite understanding the question.
Damien Watson
27,419 PointsDamien Watson
27,419 PointsYou need to do another query select to reference the anchor tag, then set its 'innerText' to the value from the previous challenge.