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)')

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

<!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>
Ben Wilson
Ben Wilson
4,323 Points

try link.textContent = inputValue;

textContent is a property, and not a function :)

1 Answer

Chuck C
Chuck C
3,957 Points

Aaah, yes, thanks !