JavaScript JavaScript and the DOM Making Changes to the DOM Modifying Elements

Brennan Formanek
seal-mask
.a{fill-rule:evenodd;}techdegree
Brennan Formanek
Full Stack JavaScript Techdegree Student 5,780 Points

how to get the value of the selected 'input' element

document.getElementById('linkName'); will return a error.

app.js
var inputValue = document.getElementById('linkName');
index.html
<!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
seal-mask
MOD
.a{fill-rule:evenodd;}techdegree seal-36
Brandon White
Treehouse Moderator

Hi 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.

still can't find the answer to that, please anybody can help with that it would be super helpful.