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 trialBrennan Formanek
Full Stack JavaScript Techdegree Graduate 14,425 Pointshow to get the value of the selected 'input' element
document.getElementById('linkName'); will return a error.
var 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>
2 Answers
Brandon White
Full Stack JavaScript Techdegree Graduate 35,771 PointsHi Brennan,
var inputValue = document.getElementById('linkName');
returns an error because it only returns the input element, not the value of the input element.
In order to get the value of the element, you have to specify that.
Here's a link to the <input> element on MDN. https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#Attributes
Go through the list of attributes and see if you can figure out which one you need to chain to the end of document.geetElementById('linkName') as a property to store the value of the input element into the inputValue variable.
Belgacem Rouabhi
Courses Plus Student 1,586 Pointsstill can't find the answer to that, please anybody can help with that it would be super helpful.