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

Alexandra Velez
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.

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>

1 Answer

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:

Hope this helps!