Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript JavaScript and the DOM (Retiring) Making Changes to the DOM Modifying Elements

Setting the text content of the a tag to be the value stored in the variable inputValue? Tried .textContent

I'm on the quiz for setting the text content of the a tag. I don't know if I'm reading into it too much, but shouldn't part of it be .textContent? When I try to preview the workspace there's no text on most of the window so it's a bit hard to figure out what's going on.

app.js
let inputValue = document.querySelector('#linkName');
inputValue = inputValue.value;
let a = document.querySelector('#link');
inputValue = a.textContent;
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>

2 Answers

Antonio De Rose
Antonio De Rose
20,885 Points

I agree that the first question does not have any issue with the reading, however, the second does, gives a little bit of mis-interpretation, however, when I get the error, I did read as many times, till I got to understand, that what the question is about.

One thing, the requirement giver, will not always, the same from person to person.

you have an 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>

<!--and if you break the questions-->
<!--q1) Store the value of the text input element in the variable inputValue.-->
<!--I do not think anyone would have an issue-->
let inputValue = document.getElementById("linkName").value;

<!--question 2-->
<!--Set the text content of the a tag to be the value stored in the variable inputValue.-->
<!--break the question, set the text content of the a tag, there is only one a tag, that too could be retreived
by using the ID and the property we have to target from JavaScript would be innerHTML,
and now, break the question again, with an additional step, set the text content of the a tag, to be the
value to be stored, in the variable inputValue-->
document.getElementById("link").innerHTML = inputValue

Thank you! I think somehow I was reading it a bit backwards.