Skip to content
Open
Changes from 2 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
19 changes: 19 additions & 0 deletions src/scripts/main.js
Original file line number Diff line number Diff line change
@@ -1 +1,20 @@
'use strict';

const gallery = document.querySelector('.gallery');
const preview = document.querySelector('.gallery__large-img');

if (gallery && preview) {
gallery.addEventListener('click', (e) => {
const link = e.target.closest('a');

if (!link) {
return;
}

e.preventDefault();

const bigSrc = link.getAttribute('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.

You correctly read the thumbnail target's href with getAttribute('href'), which preserves a relative path. However, the test suite expects that the preview's related link (the anchor that wraps the large image, if present) is updated too. After computing bigSrc you should find the preview link (for example: const previewLink = preview.closest('a')) and call previewLink.setAttribute('href', bigSrc) so the anchor's href stays a relative path as well.


preview.setAttribute('src', bigSrc);
});
}
Loading