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 Preparation

Why do you use a <span> in the <p>?

Why bother using the <span> tag in the html and the js code? We can get the same results without using span, like so: $(".spoiler").hide();

3 Answers

I figured it out. When we append the button, with out the <span> tags, the button is hidden (and I don't know why). But, when I add the <span> tags back in, the button is no longer hidden.

Perhaps you might hide only part of the content within the paragraph tags (now or in later videos)?

Yes, I figured it might be used to hide only some of the content, if the span only covered a portion of the text, but in this case, it doesn't. The span covers the entire <p>. I'm assuming they just did it, because, and that I can drop the <span> tag since I'm covering all of the text. I'll try it with multiple spoilers and apply the <span> where it only covers part of the text, to see what happens. Thanks.

<body>
    <img src="img/deathstar.png" />
    <p class="spoiler">
        <!--Spoiler:-->
        <span>Darth Vader is Luke Skywalker's Father! Noooooooooooo!</span>
    </p>

  <p class="spoiler">
        <!--Spoiler:-->
        <span>Luke and Leah are siblings</span>
    </p>
Brian Mendez
Brian Mendez
7,734 Points

Any reason I am seeing the tag very briefly right when the page loads? It's as if the JS interpreter doesn't get to the code quick enough to hide it before the user can see it.