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!

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


troy beckett
troy beckett
12,035 Points

changing src of image for gallery

I have an image gallery where I want to add a lightbox, I've looked at the lightbox course on here and its great and I'm using that code but I need to do something a bit different and need some advice.

I've got an img folder with two images one a larger version of the other what I want to do is this?

The first image that I click to trigger the lightbox has a src:

img src="red.jpg"

the second large pic has a src:

img src="red_large.jpg"

Is it possible on clicking the first image taking its src and then adding _large to the end so red.jpg becomes red_large.jpg so that when then append this to the lightbox

1 Answer

Erik McClintock
Erik McClintock
45,783 Points


For that type of functionality, you could look into the setAttribute() method of JavaScript, and you'd want to call it in your handler function that your click event triggers.