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 Perfect

Why don't we hide the button first, and then show the spoiler text?

I was wondering -- why don't we hide the button first, and then show the spoiler? In other words, why isn't the code written like this?

$("button").click(function(){ $(this).hide(); $(this).prev().show(); });

I tried it out, and it seems to be working just fine. In addition, this order of operations seems to make more sense to me -- 1st, hide the button; 2nd, show the spoiler text.

Thanks!

2 Answers

Steven Parker
Steven Parker
231,275 Points

:point_right: If you use hide instead of remove, either order will work.

It doesn't really matter which order you perform the functions, because they happen too fast for the user to detect a difference.

But be aware that in the original code, the button was not just hidden but removed, so it was important for that to happen last. Once the button is removed, no other operations relative to the button can be performed.

Thanks Steven!