Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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 :-)