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 trialSilvia Ramos
Front End Web Development Techdegree Graduate 18,318 Pointsprev()
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! :)))
1 Answer
Steven Parker
231,186 PointsThe 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?
Silvia Ramos
Front End Web Development Techdegree Graduate 18,318 PointsSilvia Ramos
Front End Web Development Techdegree Graduate 18,318 Pointsyou are an angel, thank you!