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 Styling Elements

Hamzah Iqbal
seal-mask
.a{fill-rule:evenodd;}techdegree
Hamzah Iqbal
Full Stack JavaScript Techdegree Student 11,145 Points

Why is it only hiding the first element and not all?

The code is only hiding the first element not all elements:

<!DOCTYPE html>
<html>
  <head>
    <title>JavaScript and the DOM</title>
    <link rel="stylesheet" href="css/style.css">
  </head>
  <body>
    <h1 id="myHeading">JavaScript and the DOM</h1>
    <p>Making a web page interactive</p>

                          <div class="list">



    <p class="description">Things that are purple:</p>
    <button id="toggleList">Hide List</button>
    <input type="text" class="description">
    <button class="description">Change list description</button>
    <ul>
      <li>grapes</li>
      <li>amethyst</li>
      <li>lavender</li>
      <li>plums</li>
    </ul>
                            </div>


    <script src="app.js"></script>
  </body>
</html>

The div should be correct placed.

const input = document.querySelector('input');
const p = document.querySelector('p.description');
const button = document.querySelector('button');
const toggleList = document.getElementById("toggleList");
const list = document.querySelector("list");


toggleList.addEventListener("click", () => {


     list.style.display = "none";                      


                           });
button.addEventListener('click', () => {
  p.innerHTML = input.value + ':';
});

I even tried. document.querySelectorAll("list"); The only item that is hiden, is the first element
<p class="description">Things that are purple:</p>

3 Answers

Steven Parker
Steven Parker
231,269 Points

That would work for hiding the entire div element. I thought you were asking about how to hide all the list items.

Steven Parker
Steven Parker
231,269 Points

The term "list" is not a valid HTML tag name. The correct tag name for the unordered list is "ul".

Hamzah Iqbal
seal-mask
.a{fill-rule:evenodd;}techdegree
Hamzah Iqbal
Full Stack JavaScript Techdegree Student 11,145 Points

That doesn't solve the issue. Also in the video the class in the HTML used is = "list", but that seem to work, only in the video.