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 Simple Lightbox Perform: Part 2

Tim Callan
Tim Callan
24,230 Points

Can't get the screen to turn black.

I've tried this over and over and I'm not sure what I'm doing wrong. I've tried three different browsers, Safari, Chrome and FireFox. I've also cleared the cache on all three. Still nothing. If anyone could take a look at the code I'd really appreciate it. Thanks in advance.

var $overlay = $('<div id="overlay"></div>');
  $('body').append($overlay);

$('#imageGallery a').click(function(event){
  event.preventDefault();
  var href = $(this).attr('href');
  $overlay.show();
  });
Tim Callan
Tim Callan
24,230 Points

Here is the css file:

body {
    font-family: sans-serif;
    background: #384047;
}
h1 {
    color: #fff;
    text-align: center
}

ul {
    list-style:none;
    margin: 0 auto;
    padding: 0;
    display: block;
    max-width: 780px;
    text-align: center;
}
ul li {
    display: inline-block;
    padding: 8px;
    background:white;
    margin:10px;
}
ul li img {
    display: block;
}
a {
    text-decoration: none;
}
/** Start Coding Here **/
#overlay {
background:black;
widows:100%;
height:100%;
position:absolute;
top:0;
left:0; 
}
Tim Callan
Tim Callan
24,230 Points

Here is the html:

<!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="Refferal Machine By Matthew Spiel"></a></li>
        <li><a href="images/space-juice.png"><img src="images/space-juice.png" width="100" alt="Space Juice by Mat Helme"></a></li>
        <li><a href="images/education.png"><img src="images/education.png" width="100" alt="Education by Chris Michel"></a></li>
        <li><a href="images/copy_mcrepeatsalot.png"><img src="images/copy_mcrepeatsalot.png" width="100" alt="Wanted: Copy McRepeatsalot by Chris Michel"></a></li>
        <li><a href="images/sebastian.png"><img src="images/sebastian.png" width="100" alt="Sebastian by Mat Helme"></a></li>
        <li><a href="images/skill-polish.png"><img src="images/skill-polish.png" width="100" alt="Skill Polish by Chris Michel"></a></li>
        <li><a href="images/chuck.png"><img src="images/chuck.png" width="100" alt="Chuck by Mat Helme"></a></li>
        <li><a href="images/library.png"><img src="images/library.png" width="100" alt="Library by Tyson Rosage"></a></li>
        <li><a href="images/boat.png"><img src="images/boat.png" width="100" alt="Boat by Griffin Moore"></a></li>
        <li><a href="images/illustrator_foundations.png"><img src="images/illustrator_foundations.png" width="100" alt="Illustrator Foundations by Matthew Spiel"></a></li>
        <li><a href="images/treehouse_shop.jpg"><img src="images/treehouse_shop.jpg" width="100" alt="Treehouse Shop by Eric Smith"></a></li>
    </ul>
    <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>

5 Answers

Andrew Chalkley
STAFF
Andrew Chalkley
Treehouse Guest Teacher

I changed widows:100%; to width:100%; and it worked for me.

Franklin Colbert
Franklin Colbert
4,868 Points

When you are selecting overlay you are calling the variable containing the div. Instead call the div's id

instead of this:

  $overlay.show();

try this:

  $("#overlay").show() ; 

to phrase it differently, $overlay is for adding things to the html, while using $("#overlay") lets you manipulate the overlay

Tim Callan
Tim Callan
24,230 Points

Hi Franklin, I tried that and it didn't work.

Franklin Colbert
Franklin Colbert
4,868 Points

hmmm, your code works for me. Haveyou tried checking the console with the page open to make sure the the overlay is in the html?

Also I just noticed your CSS rule "widows" may be misspelled

Tim Callan
Tim Callan
24,230 Points

Hi Franklin, Nope that still didn't work. I've been trying different things and have been stuck on this for almost a month now.

Tim Callan
Tim Callan
24,230 Points

Hi Andrew, That was the fix! The CSS for this lesson has "widows" instead of "width" written. Thank you so much!