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 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.