I have a table of 8 images that I need to sort alphabetically when I click on any of the images. The image that has been clicked goes to the first position in the first row of the table. The next position in the first row will be the image whose name is alphabetically right after the name of the first one and so on for the other images. The images are stored in an array called 'flowers'.
Here is what I have so far:
// Sort Images
let imgClick = document.getElementsByTagName('img');
for (var i = 0; i < imgClick.length; i++){
imgClick.addEventListener("click", flowers.sort((a, b) => (a.name > b.name ? 1 : -1)))
};
The images don't get sorted when I click them.