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

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">
<span style="display: none;">Darth Vader is Luke Skywalker's Father! Noooooooooooo!</span>
<button>Reveal Spoiler!</button>

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