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 trialandrew schoenherr
8,427 PointsMy code follows the link to the image. Why?
Below is my code. Seems I have something wrong in the prevent default. My overlay does not show. Instead I am following the link to the image. Where am I wrong?
// JavaScript Document
var $overlay = $('<div id="overlay"></div>'); var $image = $("<img>"); var $caption = $("<p></p>");
// an image to overlay $overlay.append($image);
// 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"); // update overlay with img linked in the link $image.attr("src", imageLocation);
$overlay.show(); //1.1, show the overlay
});
//3, when ovlay is clicked $overlay.click(function(){ // hide overlay $overlay.hide(); });
<!HTML>
<ul class="dropdown-menu" id="imageGallery">
<li><a href="../images/PizzaMenu.jpg">Pizza</a></li>
1 Answer
andrew schoenherr
8,427 PointsNevermind! Simple mistake. I was loading my js file before Jquery! Opps!