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 trialAdam Zuckerberg
22,248 Pointsprev() does not make sense
i guess i am saying it would be easier to understand this video's use of the prev(); jQuery selector if you were using it to remove or add something that actually exists in the DOM already rather than trying to teach two new confusing concepts at once - that you can append DOM elements into your html using jQuery in a .js file and the second idea that you can being that you can traverse the DOM and manipulate it. I would use an example of a DOM element that you didn't add in the js file or something. I think i get it now, but it would be nice if I could somehow see the adjacency of these elements but I can't since the button element is added with jquery in a way i don't understand (i.e. how the page loads with html and js to create adjacent elements some of which are in the html DOM and some of which are inserted somehow through jQuery
1 Answer
Vance Rivera
18,322 PointsIf you go take a look at the video again and read through the prev() description I think it will become more clear. If you inspect the DOM you will see that the button is appended right after the span spoiler messages. So on the click event when you want to reveal the specific spoiler message span you want to select the previous span element from the button you clicked in the .spoiler container. To sum it up what you have effectively done is append a button after each hidden span and created a click event that will hide the button and reveal the specific span message previous to the button clicked.