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.
prev() Hey, sorry but I didn't quite understand why she is using prev() to access the different buttons? Can someone explain this for "dummies"? haha I understood what the prev method is used for with those lists examples, but I can't get it right on this project?
Thank you! :)))
Steven Parker217,569 Points
The purpose of traversal is to get a reference to an element starting with a reference to another element.
The "prev()" method gets a reference to the element just before the one it is used on. So if you click on a button, the
$(event.target) refers to the button itself, and using "prev()" on that refers to the span just before it:
<span style="display: none">Darth Vader is ... <span> <!-- $(event.target).prev() --> <button>Reveal Spoiler</button> <!-- $(event.target) -->
Does that help?