document.querySelectorAll('img').forEach(function(img) { img.addEventListener('mouseover', function() { this.classList.add('border'); }); img.addEventListener('mouseout', function() { this.classList.remove('border'); }); });