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

Button works but text isn't showing?

After deleting the button in the HTML and adding it through jQuery, the button displays and works but the text "Reveal Spoiler" isn't showing on the button. My code looks identical, not sure what the difference is.

Steven Parker
Steven Parker
243,266 Points

If you make a snapshot of your workspace and post the link to it here we can replicate the issue, and I'll bet help you find it.

3 Answers

Nevermind, found the answer from the syntax highlighting in the forum. Was missing a > at the end of the button closing tag!

Hey Anthony I'd love to help, but could you share the code with us or a snapshot of your workspace? It's hard to help without actually seeing the code. Thanks and feel free to respond to me once you upload the code or if you have questions about how!

//Create the "Reveal Spoiler" button
const $button = $('<button>Reveal Spoiler</button');
//Append to web page
$('.spoiler').append($button);
// the spoiler text
  $('.spoiler span').hide();
//When button is pressed
  $('.spoiler button').click(function(){
//Show spoiler text
  $('.spoiler span').show();
//Hide the "Reveal Spoiler" button
  $('.spoiler button').hide();
});

Woops, sorry about that haha.