Skip to content
Open

develop #1751

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

const bigI = document.querySelector('#largeImg');
const small = document.querySelectorAll('.gallery__img');

small.forEach((img) => {
Comment on lines +4 to +6
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Task requirement violation: You must use event delegation. Instead of adding listeners to each image individually, add ONE listener to a parent element (like the gallery container) and use event.target to detect which element was clicked.

img.addEventListener('click', () => {
if (bigI) {
bigI.src = img.src;
}
});
Comment on lines +6 to +11
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Replace this loop-based approach with a single delegated event listener on a parent element. Use event.target to check if the click was on an img or a element, then update the main image accordingly.

});
Loading