Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript jQuery Basics (2014) Creating a Simple Lightbox Fixing the Simple Lightbox

missgeekbunny
missgeekbunny
37,033 Points

Final Code Challenge on Lightbox Perfect

I'm really confused. This is my code. I am looking at it and the documentation and the video and cannot figure out why I'm getting a parse error.

$("#imageGallery a").click(function( event ){
    event.preventDefault();
  var imageLocation = $(this).attr("href");

  $image.attr("src", imageLocation);

  $overlay.show();


  var captionText = $(this).children("img").attr("alt");
  $caption.text(captionText);
});

P.S. I suck at Markdown like I can't get it to work.

2 Answers

Aaron Graham
Aaron Graham
18,033 Points

It is hard to tell where the parse error is. In this challenge, you should only have to add event.preventDefault() at around line 19. Did you change anything else? I believe that this is the section of code you have above:

$("#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 alt attribute and set caption
  var captionText = $(this).children("img").attr("alt");
  $caption.text(captionText);
});

Is this the same as what you have?

P.S. To get the markdown to work, make sure you have an empty line before the first set of backticks.

missgeekbunny
missgeekbunny
37,033 Points

Thanks for that. I went back to a fresh code challenge and I guess I changed something and missed it.