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

How would you add next and previous buttons to browse the images instead of exiting on click.

http://port-80-z0zvw4893e.treehouse-app.com

//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);

//Add caption to overlay
$overlay.append($caption);

//Add overlay
$("body").append($overlay);

  // A caption

//1. Capture the click event on a link to an image
$("#imageGallery a").click(function(event){
  event.preventDefault();
  var imageLocation = $(this).attr("href");
   //1.2 Update overlay with the image linked in the link
   $image.attr("src", imageLocation);

  //1.1 Show the overlay
  $overlay.show();


  //1.3 Get child alt atribute and set caption
  var captionText = $(this).children("img").attr("alt");
  $caption.text(captionText);
});

//3 When overlay is clicked 
$overlay.click(function(){
//3.1 Hide the overlay
  $overlay.hide();
});

Also how do I format my code when asking a question ?? is there a shortcode to use?Sorry!!!

Seth Kroger
Seth Kroger
56,413 Points

You can format your code with 3 backticks (```) on the line before and after.

//Fixed Code Preview

Ps. you can edit the question to view how I fixed it.

Steven Parker
Steven Parker
229,921 Points

:x: You can't share a direct URL to your workspace, it's private just for you and only exists while you are using it.

:information_source: But you can use the snapshot function in the workspace and provide the link to that.

Here is a snapshot of my workspace. Thank you in advance! https://w.trhou.se/kxvexvsr8o