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

Alexandra Velez
seal-mask
.a{fill-rule:evenodd;}techdegree
Alexandra Velez
Front End Web Development Techdegree Student 9,313 Points

Why is the ID not being selected?

It looks like it should accept the ID associated with the input, but it's not selecting it. I've tried different variations and using other selection techniques, yet it's not working. Intuitively, it seems like it should select the item if the ID is used.

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>

1 Answer

rabin
seal-mask
.a{fill-rule:evenodd;}techdegree
rabin
Front End Web Development Techdegree Student 15,247 Points

Hey Alexandra Velez,

You have selected the correct element with the id of linkName but you are missing one thing. In order to get the value of text input, you need to use value property.

var inputValue = document.getElementById('linkName').value;
var link = document.getElementById('link').textContent = inputValue;

To learn more about value property, check out this link: https://www.w3schools.com/jsref/prop_text_value.asp

Hope this helps!