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

WordPress

Gabriel Ward
Gabriel Ward
20,222 Points

Lightbox and Wordpress

I'm trying to build a simple lightbox for my WP theme, using the code used in the jQuery Basics, Simple Lightbox course. I'm getting the overlay to show, and small blank image icon in the top left of the browser window. However in the console I'm getting the following error

http://localhost:8888/wordpress/imageLocation 404 (Not Found)

Here is my jQuery code, andy help/advice would be greatly appreciated.

jQuery(document).ready(function($) {

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


    $overlay.append($image);
    $('body').append($overlay);

    $('.gallery a').click(function(event){
        event.preventDefault();
        var imageLocation = $(this).attr('href'); //here is the problem error
        $image.attr('src', 'imageLocation');
        $overlay.show();
    });

});

1 Answer

jag
jag
18,266 Points

You are calling in a string "imageLocation" rather than calling $(this).attr('href') for starters.

 $image.attr('src', imageLocation);
Gabriel Ward
Gabriel Ward
20,222 Points

Hi jag,

Thanks for that, I needed a fresh pair of eyes to read over it. Such a simple mistake.