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

Chuck C
Chuck C
3,957 Points

I get a TypeError and I don't understand why

I get this error while running my code and I don't understand why.

First I get the input value and store it in inputValue Then I target the link a#link and store it in link.

And finally I try to change the textContent that way: link.textContent(inputValue)

And I get: TypeError: '' is not a function (evaluating 'link.textContent(inputValue)')

app.js
var inputValue = document.querySelector('#linkName').value;
var link = document.querySelector('#link');

link.textContent(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>
Ben Wilson
Ben Wilson
4,323 Points

try link.textContent = inputValue;

https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent

textContent is a property, and not a function :)

1 Answer

Chuck C
Chuck C
3,957 Points

Aaah, yes, thanks !