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 trialJack White
4,893 PointsHelp with a challenge task. I don't know what I'm doing wrong
I'm not sure if I'm reading the question wrong, or if there is something wrong with my code?
The way I understand the first question is that I need to select the <input> element with the ID #linkName and assign it to the variable inputValue, but when I then check my work it tells me I did it wrong.
It is quite late so perhaps I'm missing something or not reading properly, thanks in advance.
const inputValue = document.querySelector('input #linkName');
<!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>
Jack White
4,893 PointsAh that helps a lot! I remember learning about selecting child elements but didn't realise that a space would have a different effect. In this case I think I was just being asleep haha
Thanks for the tip Joel!
1 Answer
Piotr Manczak
Front End Web Development Techdegree Graduate 29,365 PointsTry this (you were close):
var inputValue = document.getElementById('linkName').value;
Jack White
4,893 PointsIt worked! Thanks so much for the help Piotr!
Joel Bardsley
31,249 PointsJoel Bardsley
31,249 PointsJust in case it helps you understand why your answer didn't pass the challenge, the 'input #linkName' selector you tried would be attempting to select a child element with an id of linkName that had an input element as its parent.
'input#linkName' without the space, as well as just '#linkName' would have been a valid selectors for using the querySelector method.