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

Cant's solve the task

Can't solve the task. Can someone help me to figure out what to do?

app.js
let aTag = document.querySelector('a');
let inputValue = aTag.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

You need to select the input(#linkName) for the value and select the a(#link) element to store the value of the input to its textContent property.

let inputValue = document.querySelector("#linkName").value;
let a = document.querySelector("#link");

a.textContent = inputValue

Thank u very much, Conor. I didn't clearly get the sense of task, but it passed succesfully :)

Set the text content of the a tag to be the value stored in the variable inputValue aTag.textContent = inputValue;

Why don't we need to invert them? Task says that we need to store text content of a tag in the inputValue

They ask for the content of the a element to be filled with the value of the input. So what they want to achieve is that if you tip something in the input bar it comes into the a element. so no not invert them. And glad that I could help. :)