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 Making Changes to the DOM Modifying Elements

Challenge 2 of 2 in Javascript and the DOM after changing element attributes is very confusing. Need to pass it by and

Need a solution

app.js
let inputValue.textcontent = document.querySelector('p className=info')
index.html
<!DOCTYPE html>
<html>
    <head>
      <title>DOM Manipulation</title>
    </head>
    <link rel="stylesheet" href="style.css" />
    <body>
      <div id="content">
        <label for="linkText">Link Text:</label>
        <input type="text" id="linkText" value="sample text">
        <p class="info"></p>
      </div>
    <script src="app.js"></script>
  </body>
</html>

1 Answer

It looks like you're on the second task, which builds on the first task. The first task asked you to assign the value of the input to the variable inputValue, and the second task has you take that value and assign it to the textContent of the <p> element with a class of info. You will need 2 lines of code for this.

let inputValue = document.querySelector('input').value;
document.querySelector('p.info').textContent = inputValue;

Remember that when you are referencing a class, it starts with a period ( . ), just like when you do your CSS. This allows you to append classes to elements when referencing them. As a side note, this should also work with document.querySelector('.info').textContent = inputValue; as the <p> element is the only element with the info class, but since it specifically asked you to assign it to the <p> element with a class of info, I put the element name in the querySelector.