I am trying to get in console the src of the image when I pass the mouse over the image, but I have not success and I don’t know the reason.
CODEPEN: https://codepen.io/ricardorien/pen/WNOKYMm?editors=1111
<div class="gallery">
<img class="gallery-img" src="https://source.unsplash.com/500x500/?architecture,japan">
<img class="gallery-img" src="https://source.unsplash.com/500x500/?architecture,usa">
<img class="gallery-img" src="https://source.unsplash.com/500x500/?architecture,australia">
<img class="gallery-img" src="https://source.unsplash.com/500x500/?architecture,chile">
<img class="gallery-img" src="https://source.unsplash.com/500x500/?architecture,england">
<img class="gallery-img" src="https://source.unsplash.com/500x500/?architecture,holand">
</div>
I’m trying with, but I can’t see what is wrong:
const selectedImg = document.querySelectorAll('.gallery-img')
function getSrc(e) {
const src = e.currentTarget.document.querySelector('img').src
return console.log(src)
}
selectedImg.forEach(e => {
e.addEventListener('mouseenter', getSrc)
})