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
20 changes: 20 additions & 0 deletions src/scripts/main.js
Original file line number Diff line number Diff line change
@@ -1 +1,21 @@
'use strict';

const largeImg = document.querySelector('#largeImg');
const galleryList = document.querySelector('.gallery__list');

galleryList.addEventListener('click', (e) => {
e.preventDefault();

const targetImg = e.target.closest('img');
const targetLink = e.target.closest('a');

if (targetImg) {
const bigPhoto = targetImg.parentNode.href;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Reading the thumbnail URL via targetImg.parentNode.href returns an absolute URL. Use the thumbnail link's getAttribute('href') (for example const thumbLink = targetImg.closest('a'); const bigSrc = thumbLink.getAttribute('href');) so the value stays a relative path as required by the tests.


largeImg.src = bigPhoto;
} else if (targetLink) {
const bigPhoto = targetLink.href;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Similarly, targetLink.href yields an absolute URL. Use targetLink.getAttribute('href') to read the relative path when the click target is the link itself.


largeImg.src = bigPhoto;
Comment on lines +15 to +19
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Setting largeImg.src = bigPhoto will convert the value to an absolute URL. Use largeImg.setAttribute('src', bigSrc) and also locate the preview's wrapping anchor (e.g. const previewLink = largeImg.closest('a')) and, if it exists, call previewLink.setAttribute('href', bigSrc) — include a small guard so you only set it when closest('a') returns an element.

}
});
Loading