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

aliceinwonderland
aliceinwonderland
7,679 Points

Please point me in the right direction.

I thought this would be right!!!

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

5 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi again! I'm sorry that you didn't get it worked out with my previous hints so let's take a look at what the challenge is wanting and then we'll walk through it:

// get the value stored in the input element with id linkName and assign it to inputValue
let inputValue = document.getElementById('linkName').value;

// get the anchor tag with the id "link" and change the text content to be equal to the value in inputValue
document.getElementById('link').textContent = inputValue;

The first line goes out to the DOM and gets the element with the id of "linkName". This was provided to us in the HTML and is the <input> element. Then we get the value stored in that (which will be a string) and assign it to the variable inputValue.

The second step wants you to set the link or anchor tag to have the text that is currently held by the variable inputValue. To do this we can first select the link by using its id which is "link" as defined in the HTML. Once wev'e selected the element (which again is an anchor tag) then we can set the textContent property to be equal to the string in inputValue.

Hope this helps! :sparkles:

aliceinwonderland
aliceinwonderland
7,679 Points

Thanks so much, Jennifer. My recent tries were getting closer to that but weren't as succinct. I appreciate your help.

Rob Allessi
Rob Allessi
8,600 Points

There's no intent to frustrate anyone or be sneaky. Along with what Jennifer already pointed out, another aspect to consider is that we also want our students getting use to reading fine/subtle adjustments in code. When you enter into an environment where you're proofreading others code, identifying these small and subtle changes will prove useful and important.

Scott Junner
Scott Junner
9,010 Points

Ok lesson learned. Hence forth I shall not ever put my tongue in my cheek ever again. It's dangerous and confusing for everyone involved. Panic ensues, chains of command are triggered. Clearly written words are completely overlooked and all anyone can focus on is what they fear. I didn't mean to scare anyone. I see now it was wrong. I hereby leave the forum with my head bowed low in disgrace.

I Dilate
I Dilate
3,983 Points

LOL what's wrong with calling that input linkName? You're using the input to name a link!

I Dilate
I Dilate
3,983 Points

Aliceinwonderland - do you have this sorted out now, or still stuck?

aliceinwonderland
aliceinwonderland
7,679 Points

I've got it. I was getting closer to what Jennifer gives as the correct code. I am such a beginner that I wasn't even referencing the html a first. I'm still a deer in headlights.

Scott Junner
Scott Junner
9,010 Points

So just to come at this from a different angle.

The <input> tag represents the place where a user PUTS information IN. The field where the user writes stuff. And the challenge is asking you to get what the user has put in. What you want to know is...what is the stored value the user put into the <input> element on the page.

In the challenge HTML file, the input field has an id. In your code, you're trying to access the id of the wrong element. It's trying to get the id of the <a> tag. And so, even if the <a> tag had a value attribute, it would be the wrong thing.

Those sneaky treehouse people use similar looking id names to confuse you on purpose. They are intentionally trying to frustrate you.

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

I'm inclined to disagree with your last sentence.

Those sneaky treehouse people use similar looking id names to confuse you on purpose. They are intentionally trying to frustrate you.

I have never known any Treehouse staff to be deceptive in any manner nor try to confuse people intentionally. The idea here is to provide education, not frustration.

I'm of the opinion that the names were chosen because they describe the element being looked at. The input element will ultimately hold the name of a link (it's even labeled as such with "Link name:" ) so linkName seems like a perfectly valid choice here. And the link id is the link so that name also seems appropriate to me.

Scott Junner
Scott Junner
9,010 Points

Looks like I touched a nerve there. It's just a bit of fun. Some smiling and joy and you know, making sure people don't blame themselves for not getting it the first time.

By the way, I have known every human being on the planet to be deceptive in some way at some time or another. There are no saints in treehouse, just like there are no saints anywhere else. And sometimes the deception is obvious and obviously to get you to concentrate on what you are learning. AKA: a good thing.

So I'm disinclined to acquiesce to your protest.

aliceinwonderland
aliceinwonderland
7,679 Points

thank you for your explanation, scott. it always helps to have it explained in plain english.