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

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

Arsalan Raja
Arsalan Raja
6,508 Points

in jQuery whey cant we use just hide method instead of remove.

// we can use spoiler //solution: hide spoiler to see the and show them when user interact.

// 1. Hide the spoiler $(".spoiler span").hide(); // 2. Add button $(".spoiler").append("<button>Revel Spoiler!</button>"); // 3. When button is pressed $("button").click(function() { //3.1. Show the spoiler $(".spoiler span").show(); //3.2. hide button $(this).hide(); });

1 Answer

Jeff Lemay
Jeff Lemay
14,268 Points

To the front-end user, hide and remove do basically the same thing. But with hide, you are only adding display:none to the element. With remove, you are actually taking that element out of the html.

You could hide an element and then show it again, but you can't remove an element and then show it again.

// this will hide then show the element
$(this).hide().show();
// this will remove the element and then not do anything
$(this).remove().show();
Arsalan Raja
Arsalan Raja
6,508 Points

Thanks, that's what i was thinking but was confuse a bit,, anyway thank you so much