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 trialodalis garcia
21,311 PointsI been looking at this over and over and I don't understand what it's asking me to do.
jQuery Basics Challenge Task 1 of 1
You know what? The alt attribute should be more descriptive of what the image is. The title attribute is better use for a caption in our lightbox. I've updated the index.html with placeholder text for all the alt attributes and added title attributes. Have a look for yourself in index.html file the new markup. Pay close attention to where the title attributes are now. This will be the text for our caption.
Alter the existing code to use the correct attribute for the caption.
//Problem: User when clicking on image goes to a dead end
//Solution: Create an overlay with the large image - Lightbox
var $overlay = $('<div id="overlay"></div>');
var $image = $("<img>");
var $caption = $("<p></p>");
//An image to overlay
$overlay.append($image);
//A caption to overlay
$overlay.append($caption);
//Add overlay
$("body").append($overlay);
//Capture the click event on a link to an image
$("#imageGallery a").click(function(event){
event.preventDefault();
var imageLocation = $(this).attr("href");
//Update overlay with the image linked in the link
$image.attr("src", imageLocation);
//Show the overlay.
$overlay.show();
//Get child's title attribute and set caption
var captionText = $(this).children("img").attr("alt");
$caption.text(captionText);
});
//When overlay is clicked
$overlay.click(function(){
//Hide the overlay
$overlay.hide();
});
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="css/style.css" type="text/css" media="screen" title="no title" charset="utf-8">
<title>Image Gallery</title>
</head>
<body>
<h1>Image Gallery</h1>
<ul id="imageGallery">
<li><a href="images/refferal_machine.png"><img src="images/refferal_machine.png" width="100" alt="Image of Refferal Machine" title="Refferal Machine By Matthew Spiel"></a></li>
<li><a href="images/space-juice.png"><img src="images/space-juice.png" width="100" alt="Image of Space Juice" title="Space Juice by Mat Helme"></a></li>
<li><a href="images/education.png"><img src="images/education.png" width="100" alt="Image of Education" title="Education by Chris Michel"></a></li>
<li><a href="images/copy_mcrepeatsalot.png"><img src="images/copy_mcrepeatsalot.png" width="100" alt="Image of Wanted: Copy McRepeatsalot" title="Wanted: Copy McRepeatsalot by Chris Michel"></a></li>
<li><a href="images/sebastian.png"><img src="images/sebastian.png" width="100" alt="Image of Sebastian" title="Sebastian by Mat Helme"></a></li>
<li><a href="images/skill-polish.png"><img src="images/skill-polish.png" width="100" alt="Image of Skill Polish" title="Skill Polish by Chris Michel"></a></li>
<li><a href="images/chuck.png"><img src="images/chuck.png" width="100" alt="Image of Chuck" title="Chuck by Mat Helme"></a></li>
<li><a href="images/library.png"><img src="images/library.png" width="100" alt="Image of Library" title="Library by Tyson Rosage"></a></li>
<li><a href="images/boat.png"><img src="images/boat.png" width="100" alt="Image of Boat" title="Boat by Griffin Moore"></a></li>
<li><a href="images/illustrator_foundations.png"><img src="images/illustrator_foundations.png" width="100" alt="Image of Illustrator Foundations" title="Illustrator Foundations by Matthew Spiel"></a></li>
<li><a href="images/treehouse_shop.jpg"><img src="images/treehouse_shop.jpg" width="100" alt="Image of Treehouse Shop" title="Treehouse Shop by Eric Smith"></a></li>
</ul>
<script src="//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>
10 Answers
Kelly von Borstel
28,880 PointsHi, Odalis. I think they want you to use the 'title' attribute instead of the 'alt' attribute for the caption. Here's the code. I put question mark where the change needs to occur.
//Problem: User when clicking on image goes to a dead end
//Solution: Create an overlay with the large image - Lightbox
var $overlay = $('<div id="overlay"></div>');
var $image = $("<img>");
var $caption = $("<p></p>");
//An image to overlay
$overlay.append($image);
//A caption to overlay
$overlay.append($caption);
//Add overlay
$("body").append($overlay);
//Capture the click event on a link to an image
$("#imageGallery a").click(function(event){
event.preventDefault();
var imageLocation = $(this).attr("href");
//Update overlay with the image linked in the link
$image.attr("src", imageLocation);
//Show the overlay.
$overlay.show();
//Get child's title attribute and set caption
var captionText = $(this).children("img").attr("???");
$caption.text(captionText);
});
//When overlay is clicked
$overlay.click(function(){
//Hide the overlay
$overlay.hide();
});
Ary de Oliveira
28,298 PointsDry Answer:
In line number 28 change .attr ("alt"); to .attr ("title"); My friend will work.
28 var captionText = $(this).children("img").attr("alt");
28 var captionText = $(this).children("img").attr("title");
Lotte Bloem
18,630 Points//Problem: User when clicking on image goes to a dead end //Solution: Create an overlay with the large image - Lightbox
var $overlay = $('<div id="overlay"></div>'); var $image = $("<img>"); var $caption = $("<p></p>");
//An image to overlay $overlay.append($image);
//A caption to overlay $overlay.append($caption);
//Add overlay $("body").append($overlay);
//Capture the click event on a link to an image $("#imageGallery a").click(function(event){ event.preventDefault(); var imageLocation = $(this).attr("href"); //Update overlay with the image linked in the link $image.attr("src", imageLocation);
//Show the overlay. $overlay.show();
//Get child's title attribute and set caption var captionText = $(this).children("img").attr("title"); $caption.text(captionText); });
//When overlay is clicked $overlay.click(function(){ //Hide the overlay $overlay.hide(); });
MUZ140946 Simon Taanisa
6,212 Pointsthanks lotte
MUZ140946 Simon Taanisa
6,212 Pointsthanks lotte
Gonzalo Calderon
21,653 PointsConfusingly and frustrating why do this coder give us his entire thesis
Gonzalo Calderon
21,653 PointsThe entire code does not make much sense, I may not be able to finish these track after all.
Ary de Oliveira
28,298 Pointsthe code is correct can help you...
Ary de Oliveira
28,298 PointsCorrect Answer ...
//Problem: User when clicking on image goes to a dead end //Solution: Create an overlay with the large image - Lightbox
var $overlay = $('<div id="overlay"></div>'); var $image = $("<img>"); var $caption = $("<p></p>");
//An image to overlay $overlay.append($image);
//A caption to overlay $overlay.append($caption);
//Add overlay $("body").append($overlay);
//Capture the click event on a link to an image $("#imageGallery a").click(function(event){ event.preventDefault(); var imageLocation = $(this).attr("href");
//Update overlay with the image linked in the link $image.attr("src", imageLocation);
//Show the overlay. $overlay.show();
//Get child's title attribute and set caption var captionText = $(this).children("img").attr("title"); $caption.text(captionText); });
//When overlay is clicked $overlay.click(function(){ //Hide the overlay $overlay.hide(); });
Ary de Oliveira
28,298 PointsWhen we learn a new programming language, we must continue to face, we can not hold on to small problems. keep learning.
Ary de Oliveira
28,298 PointsGonzalo Make sure you understand calculus because it will come up everywhere coding and programming and help to understand language ...
You need understanding of exactly how computers work and why they work the way they do, no just coding...
Practice a lot, move on, understand calculus makes your life easier to code the computer.
Vipin Singh
15,268 PointsAdd only title in this line of code
var captionText = $(this).children("img").attr("title");
Khan Ali Paiwandzada
5,106 Pointsput in the attribute title
MUZ140946 Simon Taanisa
6,212 PointsMUZ140946 Simon Taanisa
6,212 Pointsi am running into the same problem