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 Set Inline Styles with the style Property

Joshua Munoz
PLUS
Joshua Munoz
Courses Plus Student 7,794 Points

Issue: Set Inline Styles with the style Property (JavaScript and the DOM)

I'm running in to an issue btnToggle element in this lesson, i've been following the video step by step and have checked over my code multiple times and i can't seem to find the issue that is preventing me from hiding the list, here's the JavaScript and HTML i'm working with

const btnUpdate = document.querySelector('.btn-main');
const btnToggle = document.querySelector('btn-toggle');

btnUpdate.addEventListener('click', () => {
  const headline = document.getElementById('headline');
  const input = document.querySelector('.input-main');

  headline.className = 'grow';
  headline.textContent = input.value;
  input.value = '';
});

btnToggle.addEventListener('click', () => {
 const listContainer =  document.querySelector('.list-container');
  listContainer.style.display = 'none';

});
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>JavaScript and the DOM</title>
    <link href="css/style.css" rel="stylesheet">
  </head>
  <body>
    <div class="wrapper">
      <header>
        <h1 id="headline">My Day</h1>
        <div class="group">
          <label for="main">What's your task?</label>
          <input type="text" id="main" class="input-main">
          <button class="btn-main">Update Heading</button>
        </div>
      </header>

      <button class="btn-toggle">Hide List</button>

      <div class="list-container">
        <ul aria-live="polite">
          <li>Make coffee</li>
          <li class='highlight'>Practice JavaScript</li>
          <li>Walk the cat</li>
          <li>Watch a Treehouse video</li>
          <li class='highlight'>Go swimming</li>
          <li class='highlight'>Play my guitar</li>
        </ul>
        <button class="btn-remove">Remove Last Task</button>
      </div>
    </div>

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

1 Answer

Steven Parker
Steven Parker
229,018 Points

The code attempts to use the selector "btn-toggle" to find the button, but a class selector must be preceded by a period (".btn-toggle").

Joshua Munoz
Joshua Munoz
Courses Plus Student 7,794 Points

Thank you so much! I figured it was something simple. I was probably just looking at my screen to long that day. 😂