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

jayshi
jayshi
5,950 Points

why does the button cover the spoiler content? Do they use CSS to do that?

So the when we click the button, the spoiler appears right at where the button was. I am just wondering if they use CSS to do that, or is it related to "append()" ?

3 Answers

the .append() method appends/inserts the created <button> html element to the element with a class of spoiler:

var button = $('<button>Reveal Spoiler!</button>');

$(".spoiler").append(button);

the text inside the p elements with the class of spoiler was hidden with the . hide() method.

Carlos Alberto Del Cueto Carrejo
Carlos Alberto Del Cueto Carrejo
13,817 Points

Ella Ruokokoski great answer, I can also add that you can check in real time what a Jquery method is doing with the DOM by opening the JavaScript console , Ctrl + Shift + J on most browsers, and interacting with the buttons. All changes will be highlighted.