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 trialCamille Pilon
4,708 PointsNEED Help with: event.preventDefault();
My images still link to the source because my function does not seem to stop it.
MY CODE:
//1.Capture the click event ona link to and image
$("#imageGallery a").click(function(event){
event.preventDefault();
var href = $(this).attr("href");
console.log(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
1 Answer
gregsmith5
32,615 PointsMake sure you have an id of imageGallery
on your <ul>
tag. If you are still having trouble, try adding this line
console.log($(this));
just to see that you're getting the correct element. It should be an <a>
tag.
Jason Anello
Courses Plus Student 94,610 PointsJason Anello
Courses Plus Student 94,610 PointsHi 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.
https://teamtreehouse.com/forum/workspace-snapshots