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 trialThomas Katalenas
11,033 Points.remove("ANOTHER WAyyyy")
this didn't work is there another way to do it?
$(".spoiler span").hide();
$(".spoiler").append("<button> Reveal Spoiler!</button>");
$("button").click(function(){
$(".spoiler span").show();
$("button").remove(".spoiler");
});
1 Answer
Steven Parker
231,269 PointsYour last line would remove all button elements that have the class spoiler, and there are none like that in the accompanying HTML code. What you were trying to do is probably:
$(".spoiler button").remove();
This removes any button that is a descendant of an element with the class spoiler. This would be OK as long as there is only ONE like this on the page. The video's suggested use of $(this) limits the removal to only the button clicked and is a better solution in case the page were expanded to have multiple spoilers and buttons.