Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript jQuery Basics (2014) Creating a Spoiler Revealer Perfect

Hardip Singh Nagi
Hardip Singh Nagi
4,758 Points

prev targets previous element where? In js page, in css or index??

prev targets previous element where? In js page, in css or index?? I see creation of button before prev.show. So how should I understand what it is actually targeting? He very clearly explained in example of using prev where we use prev and what it targets(line 3). But in actual implementation there is no explanation what statement or sibling is prev targeting. A bit of hovering the mouse over targeting statement would have helped at least if not more.

Karl Jones
Karl Jones
8,761 Points

When you use append() it adds the code straight into the html file. You can view this by right clicking and inspecting the element in the browser. I copied the code below for reference:

<p class="spoiler">
<!--Spoiler:-->
<span style="display: none;">Darth Vader is Luke Skywalker's Father! Noooooooooooo!</span>
<button>Reveal Spoiler!</button>
</p>

When you use prev() it selects the previous sibling element in the html file, which, in this case, would be the span element.