Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/scripts/main.js
Original file line number Diff line number Diff line change
@@ -1 +1,18 @@
'use strict';

const container = document.querySelector('.gallery');
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no check that container exists before calling addEventListener. If .gallery is missing this will throw. Add a guard like if (!container) return; or check before attaching the listener.

const mainImage = document.querySelector('img');
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You use document.querySelector('img'), which returns the first in the document. If the first image is a thumbnail, this will update the wrong element. Select the main/preview image explicitly (for example document.querySelector('.preview img') or give the main image a dedicated class) so tests and different DOM orders behave correctly.


container.addEventListener('click', (evt) => {
const link = evt.target.closest('a');

if (!link) {
return;
}

evt.preventDefault();

const newSrc = link.href;

mainImage.src = newSrc;
});
Loading