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

Still revealing both spoilers

I followed what she was writing but for some reason my page is still showing both spoilers instead of one. Here is my code:

$('.spoiler').on('click', 'button', function(event){
  console.log(event.target);
  // show the spoiler text
  $(event.target).prev().show();
  // hide the "reveal spoiler" button
  $(event.target).hide();
});

// create the "reveal spoiler" button
const $button = $('<button>Reveal Spoiler</button>');
// append to web page
$('.spoiler').prepend($button);

// hide spoiler on page load
$('.spoiler span').hide();

// when the button is pressed
$('.spoiler button').click(function(){
 // show the spoiler text
  $('.spoiler span').show();
  // hide the "reveal spoiler" button
  $('.spoiler button').hide();
});

1 Answer

Hi Karen, I'd be happy to help you with this. Are you able to share the HTML you're working with as well? Would you mind posting a link of the video you're working through too?