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 trialShannon Kagey
2,587 PointsCorrect code not working
I believe the code I added in the jQuery Basics challenge is correct yet the page is telling me otherwise. Here is what I have updated:
$("this.button").remove(); });
1 Answer
Brittany Drollinger
6,160 PointsWhere the code is being used:
$("button").click(function(){
$(".spoiler span");
//3.2, Get rid of button
$(this);
});
Since you are already using the jQuery selector to bind the click function to buttons (note that it is button elements not elements with the class of button since there is no '.') you only need to use 'this' when inside the click function. 'This' refers back to that element (in this case the button element that gets clicked).
So you can simply do:
$(this).remove();
The "this" keyword in Javascript is a reference that changes depending on scope/context. With jQuery, we wrap the this with the jQuery object so we can call jQuery methods and functions - like remove().