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 4

OMER FARUK BULGAK
OMER FARUK BULGAK
5,544 Points

why we dont use quotation mark for "href" attribute? I put the question mark next to the live I am having problem?

//Problem: User when clicking on image it goes to dead end //Solution: create and overlay with the larger image - Lightbox

var $overlay = $('<div id="overlay"></div>'); var $image = $("<img>");

// 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.preventDefault(); var href = $(this).attr("href"); // Update overlay with the image linked in the link

$image.attr("src", href); // ???????????????????????????????????????????????????????? // Show the overlay $overlay.show();

// Get child's alt attribute and set caption

});

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

2 Answers

Steven Parker
Steven Parker
231,269 Points

You don't put quotes around variable names.

On this line :point_right: $image.attr("src", href); :point_left: this href is the variable you set on the previous line.

It was a bit hard to evaluate the unformatted code. In future questions, please use the instructions for code formatting in the Markdown Cheatsheet pop-up below the "Add an Answer" area. :arrow_heading_down:

You can also make a snapshot of your workspace and post the link to it here.

The href is the variable we just created using var href = $(this).attr("href");

The syntax for adding attr method is attr(attribute name, value);

There is no mention of quotation mark in the syntax. So which means you don't have to use quotation mark next to href.