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 1

Camille Pilon
Camille Pilon
4,708 Points

NEED Help with: event.preventDefault();

My images still link to the source because my function does not seem to stop it.


//1.Capture the click event ona link to and image
$("#imageGallery a").click(function(event){
  var href = $(this).attr("href");
  //1.1 Show the overlay.
   //1.2 Update overlay with the image linked in the link
   //1.3 Get child alt attribute and set caption


//2. Add overlay
  //2.1 An image
  //.2.2 A caption
//3. When overlay is clicked
  //3.1 Hide the overlay

Hi Camille,

Can you verify whether or not the href value is being logged to the console?

If you're doing this in workspaces you can post a snapshot of your workspace which will make it easier to troubleshoot.


1 Answer

Make sure you have an id of imageGallery on your <ul> tag. If you are still having trouble, try adding this line


just to see that you're getting the correct element. It should be an <a> tag.