I recently asked a question about changing the height of images when clicking on them using vanilla JS. A helpful user named Butalin provided me with a working function, but there seems to be an issue - if I click on one image to change its height and then click on another image without returning to the first one, the height of the first image does not revert back to normal as expected. Is there a way to achieve this behavior?
Below is the code I am using:
var element = document.querySelectorAll('.imgclasstosize');
element.forEach(el => {
el.addEventListener('click', function(event) {
if (event.target.style.height == '500px') {
event.target.style.height = '80px';
} else {
event.target.style.height = '500px';
}
});
});
And here is the HTML code for the images:
<img class="imgclasstosize" src="https://assets.picspree.com/variants/FRgeQ4d3pFXszVF7QW9VBgFQ/f4a36f6589a0e50e702740b15352bc00e4bfaf6f58bd4db850e167794d05993d">
<img class="imgclasstosize" src="https://assets.picspree.com/variants/RXCuAnyzqoapjkZQuhDFwBMs/f4a36f6589a0e50e702740b15352bc00e4bfaf6f58bd4db850e167794d05993d">