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 trial

JavaScript jQuery Basics (2014) Creating a Spoiler Revealer Perform: Part 3

eric nzenga
eric nzenga
2,661 Points

remove() vs hide()

I tried using hide() instead of remove() and it worked too. Why remove() is a better choice? Thank you

2 Answers

Josh Alling
Josh Alling
17,172 Points

It depends on what you want to accomplish, because remove and hide do different things. Hide will change the css to display none, so that element is still in the dom, but it's hidden. Remove will actually delete the element and it's contents. If you need to hide an element temporarily and show it again later, use hide(). If you know that you won't need the element on the page anymore, use remove().

eric nzenga
eric nzenga
2,661 Points

Thank Josh, it makes more sense to me now :-)