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 Changing Element Attributes

second task on modifying elements. I am stuck

I am stuck with the second task. Can anyone clarify it? Next, set the text content of the <a> element with the ID link to the value stored in inputValue.

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

5 Answers

Linas Mackonis
Linas Mackonis
7,071 Points

Hi Krystian,

The correct solution is this:

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

I really appreciate your help. Would the following perform the same?

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

Emmanuel C
Emmanuel C
10,636 Points

It wont, youre storing the value of linkName in inputValue, and youre storing the textContext of link in textContext. Then youre assigning what was in inputValue to whatever is in textContent. You dont actually change any of the elements themselves, but over writing the value of one variable with the value of another variable.

Linas Mackonis
Linas Mackonis
7,071 Points

This basically says that whatever you will type in the input field, will become the content of an <a> element with the ID of link

Linas Mackonis
Linas Mackonis
7,071 Points

No, there's a difference: textContent should be equal to the inputValue;

But you won't get the right answer this way if you're completing the challenge :)

I was stuck on this as well so thank you Linas for the correct answer. I understand the first part of the challenge but I don't understand why the second part is like this:

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

but not this (reverse):

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

inputValue already holds the value of #linkName so why can this not be done?