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

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

list.addEventListener('click', (e) => {
e.preventDefault();
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Calling e.preventDefault() unconditionally prevents the default action for all clicks inside the list (including non-anchor clicks). Consider moving preventDefault() into the branches that handle anchor clicks (or only call it when the click target or its closest ancestor is an a) so other clicks don't get their default behavior blocked.


if (e.target.tagName === 'IMG') {
largeImg.src = e.target.closest('a').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.

When handling the IMG case you call e.target.closest('a').href without checking that closest('a') actually found an anchor. Add a null-check (or guard) before accessing .href to avoid potential runtime errors if the markup changes.

} else if (e.target.tagName === 'A') {
largeImg.src = e.target.href;
}
});
Loading