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

Madeline Yao
seal-mask
.a{fill-rule:evenodd;}techdegree
Madeline Yao
Full Stack JavaScript Techdegree Student 9,611 Points

My code cannot show the list

Hello, I tried to rework the example in the video but the thing is that I cannot let the list to be shown again and I only can hide the list. Could anyone please help me with the bug inside the code? Thank you!

Adam Beer
Adam Beer
11,314 Points

Please show your whole code.

Code

Wrap your code with 3 backticks (```) on the line before and after. If you specify the language after the first set of backticks, that'll help us with syntax highlighting.

      ```html
      <p>This is code!</p>
      ```
Madeline Yao
seal-mask
.a{fill-rule:evenodd;}techdegree
Madeline Yao
Full Stack JavaScript Techdegree Student 9,611 Points

a. Here is the code from app.js: const p = document.querySelector('p'); const input = document.querySelector('input'); const button = document.querySelector('button'); const list = document.querySelector('.list'); var hide_button = document.querySelector('#hide');

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

hide_button.addEventListener('click', ()=>{ if(list.style.display !== 'none'){ list.textContent = 'show list'; list.style.display ==='block'; } else{ list.textContent = 'hide list'; list.style.display === 'none'; }

                         });

b. Here is the code from index.html: <!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>

<button id="hide">Hide list</button>
<div class="list">
<p>Things that are purple:</p>
<input type="text" class="blanks">
<button class="button">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>

Adam Beer
Adam Beer
11,314 Points

Please fixed your backticks.

Adam Beer
Adam Beer
11,314 Points

app.js

const p = document.querySelector('p'); 
const input = document.querySelector('input'); 
const button = document.querySelector('button'); 
const list = document.querySelector('.list'); 
var hide_button = document.querySelector('#hide');

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

hide_button.addEventListener('click', ()=>{ 
   if(list.style.display !== 'none') { 
        list.textContent = 'show list'; 
        list.style.display ==='block'; 
   } else { 
        list.textContent = 'hide list'; list.style.display === 'none'; }
});

index.html

<!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>

   <button id="hide">Hide list</button>
   <div class="list">
      <p>Things that are purple:</p>
      <input type="text" class="blanks">
      <button class="button">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>

2 Answers

Adam Beer
Adam Beer
11,314 Points

The ` symbol similar to the apostrophe.

Adam Beer
Adam Beer
11,314 Points

First you forgot inside from the code content the first <p></p> element after the <h1 id="myHeading"></h1>. Second the first button id="toggleList" and the second button id="description".

<p>Making a web page interactive</p>

Please look again the video. The app.js file is bit too different.