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

Nick Robin
Nick Robin
Full Stack JavaScript Techdegree Student 6,081 Points

why the below not an acceptable answer:

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

I'm getting really frustrate with this question. In testing, this method works fine. I see others had this question too:

https://teamtreehouse.com/community/set-the-text-content-of-the-a-tag-to-be-the-value-stored-in-the-variable-inputvalue

app.js
var inputValue = document.getElementById("linkName").value;
document.getElementById('link').text = inputValue;
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

turaboy holmirzaev
turaboy holmirzaev
12,570 Points

Use “textContent” instead of “text”