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 trialMustafa Khan
6,224 PointsI am confused
The error is saying that it needs to have the value of input, but does that mean the type or the id?
let inputValue = document.getElementById('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>
3 Answers
Kyle Adams
10,180 PointsYour current answer:
let inputValue = document.getElementById('linkname');
Is close, but there are two problems:
You must be case specific with the ID. So while
linkname
is not an ID in the HTML,linkName
is. It's easy to overlook but will break your code!Using
getElementByID( 'linkName' );
will simply find the ID tag in the document. To grab the element and find it's value, use.querySelector( '#linkName' );
Then, to find the value of that query, you can use the .value
property, like this:
let inputValue = document.querySelector( '#linkName' ).value;
Calin Bogdan
14,921 PointsHello!
Firstly, the ids are case sensitive. Therefore, document.getElementById('linkname') won't return the element with ID linkName. Secondly, inputValue should store the value of the element, not the element itself. The value of the input is the text you type inside that textbox.
Hope it helped!
Mustafa Khan
6,224 PointsHow would I store the value of the element?
Calin Bogdan
14,921 PointsThe element object has a property named value. Thereβs the value of the element.
Mustafa Khan
6,224 PointsI dont know how to do that