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 trialYashwanth Yash
10,947 PointsWhy shouldn't we use button instead this?
I have used "button" selector instead of "this" and it works the same. Is there any disadvantage of using button?
2 Answers
Konstantin Kovar
16,003 PointsIf you were to add another button to your page, it would disappear then aswell. In fact ALL the elements with that specific tag would would be the target of whatever function you're calling on it, which can be what you want in some cases.
The "this" keyword makes sure only this one specific element is targeted.
Konstantin Kovar
16,003 PointsYou could do something like that, but then you would have to rewrite this for every specific button. Remember to keep your code DRY (don't repeat yourself).
Jenna Malone
7,173 PointsOh ok. Makes sense. Thank you!
Jenna Malone
7,173 PointsJenna Malone
7,173 PointsYeah but cant you just get more specific? I used:
$(.spoiler button).remove();
and it did the same thing. I also used the original method he taught us hide instead of remove and it still worked.