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 Preparation

Ozgur Parlakkilic
Ozgur Parlakkilic
8,399 Points

would this work as an Answer to the project;

//1, hide button //2, add a button //3, when button pressed //3.1, show spoiler //3.2, get rid of button

$(".spoiler").hide(); $( "button" ).click(function() { $( ".spoiler" ).toggle().toggleClass('active'); $("button").hide(); });

1 Answer

Steven Parker
Steven Parker
231,269 Points

:point_right: The code above would perform differently from the exercise objective.

Why not try it yourself in the workspace and see? I'll tell you what it would do, but seeing it for yourself would be more memorable.

Anyway, the value of using $(this) as in the teacher's example is that each button will only reveal the spoiler associated with it. Your code above would cause either button to reveal both spoilers, and hide both buttons.