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 trialLe Var Range
Front End Web Development Techdegree Student 18,011 PointsI am having a little trouble figuring out why my click function for my interactive photo album not working?
''' js
// JavaScript Document
var $arrow1 = $("<img id='arow1' src='icon/arrows.svg'/>" );
var $arrow2 = $("<img id='arow2' src='icon/arrows-1.svg'/>");
var $para = $("<p></p>");
var $image = $("<img id='imgov'>");
var $overlay = $("<div id='overlay'></div>");
var $main = $(".pic-nav li a");
var $nextImage = function() {
$(this).parent().next().children();
};
var $previousImage = function() {
$(this).parent().prev(),children();
};
// AdDiNg OvErLaY aNd iMaGe WiTh TeXt //
$overlay.append($image);
$overlay.append($arrow1);
$overlay.append($arrow2);
$overlay.append($para);
$("body").append($overlay);
// iMaGe CliCk FuNcTiOn ShOwInG oVeRlAy //
$main.click( function(e) {
e.preventDefault();
var imageLoc = $(this).attr("href");
$image.attr("src", imageLoc);
$overlay.show();
var captionTex = $(this).children("img").attr("alt");
$para.text(captionTex);
});
$arrow1.click( function() {
var $nextLoc = $nextImage.attr("href");
$image.attr("src" , $nextLoc );
var $nextCaptionText = $nextImage.attr("alt");
$para.text( $nextCaptionText );
});
$arrow1.hover( function() {
$arrow1.toggle();
});
$arrow2.hover( function() {
$arrow2.toggle();
});
$image.click( function() {
$overlay.hide();
});
``` js
1 Answer
Steven Parker
231,198 PointsI see a few things right off:
- Calling toggle on hover makes the element's visibilty unstable. While not visible, it can't be clicked.
- The click handler calls $nextImage, which then tries to get the children of the next item after the parent, but the parent of the images is the overlay div, and it has no next element.
- $nextImage and $previousImage don't return anything
- There is a click handler for $arrow1, but not $arrow2
- $previousImage has a comma and a space where there should be a period
There's a bit more to do, but hopefully that will get you started.