Tell us what’s happening:
I’ve updated the original post – I’ve now passed all the tests except for test 14.
I’m still stuck on test 14, even though the preview looks fine.
Test 14
When you click one of your .gallery-item elements, the .lightbox element’s display property should be set to flex to make .lightbox and the two elements within it visible.
Your code so far
<!-- file: index.html -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Lightbox Viewer</title>
<link rel="stylesheet" href="./styles.css" />
</head>
<body>
<h1>Museum Gallery</h1>
<div class="gallery">
<img
class="gallery-item"
src="https://cdn.freecodecamp.org/curriculum/labs/stonehenge-thumbnail.jpg"
width="250"
height="150"
/>
<img
class="gallery-item"
src="https://cdn.freecodecamp.org/curriculum/labs/storm-thumbnail.jpg"
width="250"
height="150"
/>
<img
class="gallery-item"
src="https://cdn.freecodecamp.org/curriculum/labs/trees-thumbnail.jpg"
width="250"
height="150"
/>
</div>
<div class="lightbox">
<button id="close-btn">×</button>
<img id="lightbox-image" />
</div>
<script src="./script.js"></script>
</body>
</html>
/* file: styles.css */
body {
display: flex;
position: relative;
flex-direction: column;
align-items: center;
justify-content: center;
border: 2px;
}
.gallery {
display: flex;
flex-direction: row;
}
.gallery-item {
margin: 2px;
}
.lightbox {
display: none;
background-color: gray;
width: 100%;
height: 100%;
position: fixed;
top: 0;
left: 0;
}
/* file: script.js */
const gallery = document.querySelector(".gallery");
const gitem = document.querySelector(".gallery-item");
const lightbox = document.querySelector(".lightbox");
const lbimage = document.getElementById("lightbox-image");
const closeBtn = document.getElementById("close-btn");
gallery.addEventListener("click", (event) => {
lightbox.style.display = "flex";
lbimage.src = event.target.src;
lbimage.src = lbimage.src.replace("-thumbnail", "");
});
closeBtn.addEventListener("click", () => {
lightbox.style.display = "none";
});
lightbox.addEventListener("click", () => {
lightbox.style.display = "none";
});
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:142.0) Gecko/20100101 Firefox/142.0
Challenge Information:
Build a Lightbox Viewer - Build a Lightbox Viewer
https://www.freecodecamp.org/learn/full-stack-developer/lab-lightbox-viewer/build-a-lightbox-viewer
What test is test 14? Which lines of code do you think satisfy this test?
@JeremyLT
Test 14
When you click one of your .gallery-item elements, the .lightbox element’s display property should be set to flex to make .lightbox and the two elements within it visible.
Before I click one of .gallery-item elements.
The HTML looks like
<div class="lightbox">...</div>
After clicking
The HTML looks like
<div class="lightbox" style="display: flex;">...</div>
Where do you trigger the click event?
As of triggering an event I use Bubbles property.
Each time I click on . gallery-item which is a child element.
The parent element gallery listens for this click and triggers the click event.
<div class="gallery">
<img class="gallery-item" />
<img class="gallery-item" />
<img class="gallery-item" />
</div>
ILM
September 9, 2025, 7:22pm
6
unfortunately the event this is tested with doesn’t bubble
ok, the one of the .gallery-items bubbles, but most events in the tests don’t
I would try adding the event directly to the element the test is checking.
@ILM
@JeremyLT
I’ve looked at similar posts on the topic “Build a Lightbox Viewer – Build a Lightbox Viewer.” Since all three child elements share the same class, .gallery-item, I take it you mean that when one of the three child elements is clicked, all three should be selected as well. Is that correct?
The instructions for test 14 don’t seem very clear to me – they feel a bit ambiguous.
ILM
September 9, 2025, 8:09pm
9
no, they are all tested indipendently
---
id: 66db57ad34c7089b9b41bfd6
title: Build a Lightbox Viewer
challengeType: 25
dashedName: build-a-lightbox-viewer
demoType: onClick
---
# --description--
A lightbox is used on websites to showcase multimedia content in a more engaging way through use of a popup or modal window over the page's main content.
In this lab, you will create a lightbox gallery that displays full-size images when a thumbnail is clicked. For each image, two versions are provided: a thumbnail and a full-size image. The full-size image is the same as the thumbnail, but without the `-thumbnail` suffix.
**Objective:** Fulfill the user stories below and get all the tests to pass to complete the lab.
**User Stories:**
1. You should have a `div` with a class of `gallery` within your `body`.
1. Within the `.gallery` element, you should have three image thumbnails, each with a class of `gallery-item`. You should use the following links for thumbnail images:
This file has been truncated. show original
I wonder if it’s a timing issue, I have seen it a bit more after some recent updates
@ILM
@JeremyLT
@pkdvalis
@jwilkins.oboe
I followed a step from this post:
Tell us what’s happening:
Okay so can anyone please tell me why I pass tests 14&15 when I use querySelector but fail when I use querySelectorAll?
The click only works for the first picture but I pass the tests and when I use all the click doesn’t work and i fail them. What is going on!
Your code so far
<!-- file: index.html -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Lightbox Vie…
Using querySelectorAll together with a loop solved the issue with test 14.
However, I’m still wondering why the bubbles property isn’t acceptable.
I wanna brush up on using querySelectorAll with a loop — any course in this curriculum you’d recommend?
ILM
September 10, 2025, 6:48pm
13
I don’t remember everything in the curriculum that well
dhess
September 10, 2025, 7:07pm
14
const highlightedItems = userList.querySelectorAll(“.highlighted”);
highlightedItems.forEach((userItem) => {
deleteUser(userItem);
});
Here’s an example from MDN , which demonstrates that you can loop over the NodeList returned by querySelectorAll() just like an array.
@ILM
@JeremyLT
@dhess
I’m starting to realise that using addEventListener inside a forEach is kind of like having a for loop outside an if statement that checks whether an event, like a click or mouseover, has happened.
“This bit of code adds an addEventListener inside a forEach after selecting multiple elements with querySelectorAll. It wasn’t the most straightforward concept to pick up from the curriculum, but it’s starting to make sense now.”