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 trialJess Hines
5,411 PointsSpoiler! Shorter code.
I can't resist perfecting when I can, and since I was already looking at the jQuery API documentation, I noticed the children()
and toggle()
functions, and came up with this. Any problems with doing it this way?
$('.spoiler span').hide();
$('.spoiler').append('<button>Reveal spoiler!</button>');
//The span with the spoiler text is now hidden, and the button is visible
//When any of the .spoiler paragraphs are clicked, toggle the visibility
//of that paragraph's children so what's visible is hidden and what was hidden becomes visible.
$('.spoiler').click(function() {
$(this).children().toggle();
});
1 Answer
Young Bae
18,429 Pointshaha the button is also showed up again when the spoiler is clicked. I like it! :)
Arun Pingaley
6,827 PointsArun Pingaley
6,827 PointsNice! Thank you