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

Brennan Formanek
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.

var inputValue = document.getElementById('linkName');
<!DOCTYPE html>
        <title>DOM Manipulation</title>
    <link rel="stylesheet" href="style.css" />
        <div id="content">
            <label>Link Name:</label>
            <input type="text" id="linkName">
            <a id="link" href=""></a>
        <script src="app.js"></script>

2 Answers

Brandon White
.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.

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.