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 jQuery Basics (2014) Creating a Spoiler Revealer Perform: Part 1

Creating a spoiler revealer -> Perform: part 1.. Whats wrong with my code?

/*
WHY DOES'NT THE BUTTON APPEAR?
*/


//1. Hide Spoiler
$(".spoiler").hide();
//2. Add button
$(".spoiler").append("<button>Reveal Spoiler!</button>");

3 Answers

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,858 Points

In the code above you were hiding the entire .spoiler but also putting the button there. You should have only been hiding the <span> in the .spoiler.

$(".spoiler span").hide();

This way the button in .spoiler is still visible, but the "Spoiler" in the <span> is hidden.

Sean T. Unwin
Sean T. Unwin
28,690 Points

`$('spoiler') is still hidden.

Try adding .show() to the end of the append() line.

$(".spoiler").append("<button>Reveal Spoiler!</button>").show();

Weird because my code is exactly like his in the video , he is not using .show() yet the button shows in the video! I am quite confused here.

I started a brand new workspace and rewrote my code and now it works!!! There must have been a semicolon I was missing somewhere or something.. who knows..? =)