Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript and the DOM Making Changes to the DOM Modifying Elements

Joel Rothstein
Joel Rothstein
6,062 Points

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

Jason Larson
Jason Larson
7,734 Points

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.