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 trialIvana Lescesen
19,442 PointsCan somewhere explain this please?
Why do we add the <span> tag to the paragraph ?
5 Answers
Aaron Selonke
10,323 PointsHi Ivana There is no reason for the Span there in the example. You can move the CSS rule for color: #dae1e4; to the spoiler class in the CSS, and it will behave the same.
In the scenario that Andrew presents in the video, he wants you to imagine that some design team in your office just gave you this website and you need to add the JavaScript. Who knows why the design team used the span tag.... Maybe they are planning to add other text next to it to be styled differently. But you really don't know.
Just focus on the jQuerying while not altering the HTML as much as possible.
Ivana Lescesen
19,442 PointsThank you :)
Aaron Selonke
10,323 PointsYour welcome, When doing Andrew's courses, you'll notice that he gives a list of methods in the teachers notes. Try stopping the video and puzzle out how to do each before he explains it by reading the method documentation he provides. After trying this, I really appreciate his teaching style.
Ivana Lescesen
19,442 PointsThanks again :)
Jeremiah Bushau
24,061 PointsHi, the purpose of span is to group inline-elements in a document or add a hook to some text or part of a document. The <span> tag itself creates no visual change. In this case it is targeted in the CSS to give a color property to the text inside of it. You can see this at the bottom of the style.css file in workspaces
.spoiler span {
color: #dae1e4;
}
You can read more about it here -> http://www.w3schools.com/tags/tag_span.asp
Ivana Lescesen
19,442 Points<!DOCTYPE html>
<html>
<head>
<title>Star Wars Spoilers</title>
<link rel="stylesheet" href="css/style.css" type="text/css" media="screen" title="no title" charset="utf-8">
</head>
<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 Leia are siblings. Ew.</span>
</p>
<script src="http://code.jquery.com/jquery-1.11.0.min.js" type="text/javascript" charset="utf-8"></script>
<script src="js/app.js" type="text/javascript" charset="utf-8"></script>
</body>
</html>
//Solution: Hide spoilers and reveal them through user interaction
//1, Hide spoiler
$(".spoiler span").hide();
//2, Add a button
$(".spoiler").append("<button>Reveal Spoiler!</button>");
//3, When button pressed
$("button").click(function(){
//3.1, Show spoiler next to the button clicked
$(this).prev().show();
//3.2, Get rid of button
$(this).remove();
});
Ozgur Parlakkilic
8,399 Points$(".spoiler").hide(); $( "button" ).click(function() { $( ".spoiler" ).toggle().toggleClass('active'); $("button").hide(); });
Aaron Selonke
10,323 PointsAaron Selonke
10,323 PointsWhere is the paragraph that your referring to?