Tell us what’s happening:
My all tests passed in this project but my project is not working properly.
When I click on 2nd and 3rd picture nothing happens but I am sure I have done everything correctly.
Please guide me on this.
Your code so far
<!-- file: index.html -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Lightbox Viewer</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="gallery">
<img src="https://cdn.freecodecamp.org/curriculum/labs/stonehenge-thumbnail.jpg" class="gallery-item pic1">
<img src="https://cdn.freecodecamp.org/curriculum/labs/storm-thumbnail.jpg" class="gallery-item pic2">
<img src="https://cdn.freecodecamp.org/curriculum/labs/trees-thumbnail.jpg" class="gallery-item pic3">
</div>
<div class="lightbox"><span id="close">×</span>
<img id="lightbox-image">
</div>
<script src="script.js"></script>
</body>
</html>
/* file: script.js */
const lightBox = document.querySelector(".lightbox");
const photo = document.querySelector(".gallery-item");
const closeBtn = document.querySelector("#close");
const largePic = document.querySelector("#lightbox-image");
const pic1 = document.querySelector(".pic1");
const pic2 = document.querySelector(".pic2");
const pic3 = document.querySelector(".pic3");
photo.addEventListener("click", () => {
lightBox.style.display = "flex"
});
closeBtn.addEventListener("click", () => {
lightBox.style.display ="none";
});
lightBox.addEventListener("click", () => {
lightBox.style.display ="none";
})
pic1.addEventListener("click", () => {
largePic.setAttribute("src", "https://cdn.freecodecamp.org/curriculum/labs/stonehenge.jpg");
});
pic2.addEventListener("click", () => {
largePic.setAttribute("src", "https://cdn.freecodecamp.org/curriculum/labs/storm.jpg");
});
pic3.addEventListener("click", () => {
largePic.setAttribute("src", "https://cdn.freecodecamp.org/curriculum/labs/trees.jpg");
});
/* file: styles.css */
.lightbox {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.6);
display: none;
}
#close {
cursor: pointer;
}
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36
Challenge Information:
Build a Lightbox Viewer - Build a Lightbox Viewer