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

Nazeim Brame
Nazeim Brame
6,544 Points

Lost

This entire section has been confusing me. I'm struggling to grasp the concept.

app.js
var inputValue = document.getElementById('linkName').value;

var inputValue= linkName.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>

3 Answers

Xavier Ritch
Xavier Ritch
6,999 Points

Hope you got this one figured by now but if not, the challenge task is asking you to set the textContent of the <a> tag equal to the value of the inputValue variable. So first we would select the <a> tag with getElementById and then call textContent on it, then store that in our variable So it should look something like this:

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

document.getElementById('link').textContent = inputValue;

hope this helps!

rydavim
MOD
rydavim
Treehouse Moderator 18,109 Points

Okay, so assuming you're working on Task 2 you'll need to be setting the text value, rather than creating a new variable. Here's some pseudo-code to get you started.

// use the same document.getElementById that you've used previously to grab the element 'link'
// you'll then want to chain it into a method for text content (textContent)
// and set that equal to the variable you created in the first task

If you're having trouble with the syntax, try taking a look at the w3 page for textContent.

Hopefully that helps get you on the right track, but please let me know if you still have trouble and we can work through a solution together. Happy coding!

Nazeim Brame
Nazeim Brame
6,544 Points

var inputValue = document.getElementById('link').textContent;

How do I set it equal to the inputValue variable?

I tried

let input = inputValue;

Steven Parker
Steven Parker
195,592 Points

Task 2 says, 'Next, set the text content of the <a> element with the ID link to the value stored in inputValue."

So the left side of the assignment will select the element with the ID of "link", and access the text content attribute, and the right side of the assignment will be the value you got in task 1 ("inputValue").

And you won't need another "let" or "var" since no new variables are being created.

Nazeim Brame
Nazeim Brame
6,544 Points

var inputValue = document.getElementById('link').textContent;

How do I assign the value from task 1 onto the right side??? It's confusing saying it like that because I thought there could only be 1 '=' per line of code.

Would it be

var inputValue = document.getElementById('link').textContent = ("inputValue"); ???

Steven Parker
Steven Parker
195,592 Points

Closer, but you don't re-create the variable so you'll have only one assignment operator:

document.getElementById('link').textContent = inputValue;