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

Daniel Coria
seal-mask
.a{fill-rule:evenodd;}techdegree
Daniel Coria
Front End Web Development Techdegree Student 5,380 Points

I don't understand what this task is asking me to do

On the second task. "Set the text content of the a tag to be the value stored in the variable inputValue." I'm having a hard time understanding this wording. What 'text content' from the <a> tag? And, I have already stored the .value of inputValue from the previous task. Am I supposed to reasign the value of inputValue to the 'text' of the <a> tag? I would really appreciate any feedback. I'm still pretty new here.

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

inputValue.value = document.querySelector('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>

3 Answers

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

Hi there, Daniel! The challenge is asking you to change the text inside the link or anchor tag to the text that's currently inside the text field. You've already gotten the text from the text field and assigned it to a variable. So I'm going to give some hints and I think you can get it from this:

  • First select the anchor tag
  • The anchor tag has an ID that makes it easily selectable
  • You can use the textContent and assign the value stored in the inputValue to what you've selected
  • Remember that we assign from right to left. x = 10; The variable x will have 10 assigned into it
  • Your inputValue will be on the right side of the equals sign

I think you can get it with these hints, but let me know if you're still stuck! :sparkles:

Daniel Coria
seal-mask
.a{fill-rule:evenodd;}techdegree
Daniel Coria
Front End Web Development Techdegree Student 5,380 Points

Thank you Jennifer! I was able to get past it with your help. I don't know if I'm allowed to post my code here to show my work (in case it gives away the answer for other readers). Thank you for your response and for helping me.

John Knotts
seal-mask
.a{fill-rule:evenodd;}techdegree
John Knotts
Full Stack JavaScript Techdegree Student 10,836 Points

Hi Jennifer... I fully understand the concept and with your clarification this is no problem at all, but I just wanted to chime in because the wording of that question is VERY confusing. I also thought I was supposed to reassign the value of inputValue.

thanks Jennifer Nordell great feedback!