I have two images and would like both to log another text. How can I control which element is used within querySelectorAll?
let elements = document.querySelectorAll('.penguin').forEach(function(elem) {
elem.addEventListener('click', function() {
console.log('Stackoverflow');
});
});
.penguin {
height: 100px;
}
<img class="penguin" src="https://upload.wikimedia.org/wikipedia/commons/thumb/b/b0/NewTux.svg/1707px-NewTux.svg.png">
<img class="penguin" src="https://upload.wikimedia.org/wikipedia/commons/thumb/b/b0/NewTux.svg/1707px-NewTux.svg.png">
I thought about using elem[0] but that doesn't work for me.
querySelector()to just select the first one.Stackoverflowand the second oneHello World. Isn't that possible?