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

Problems with setting inline styles with the style property

The video in the below link provides coding for the associated workspace.

video: https://teamtreehouse.com/library/set-inline-styles-with-the-style-property workspace: https://teamtreehouse.com/workspaces/42061095

Here's the code presented in the video.

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.addEventLister('click', () => {
  const listContainer = document.querySelector('.list-container');
  listContainer.style.display = 'none';
});

The above coding is supposed allow a button on the webpage to show and then hide a list. I've copied it exactly and yet it won't work.

What am I doing wrong?

2 Answers

Steven Parker
Steven Parker
231,007 Points

Maybe not quite "exactly". :see_no_evil: There's a spelling error where the code has "addEventLister" instead of "addEventListener".

Also, the code above will only hide the list, code to show it again still needs to be added.

For future questions, be aware that you can't share a direct URL to your workspace, it's temporary and only exists while you are using it. But you can use the snapshot function in the workspace and provide the link to that.

Damn! I went over that coding several times and somehow I didn't see that mistake. Once again, thanks for your help.