It is a image gallery code on clicking the imgs(8 images) current image(main image) get changed .But how the forEach knows that we are clicking the respective image.If its jquery we use this keyword ?
The .forEach() method iterates over all elements in the NodeList, and the iterator function takes the current element as its first argument (which is your aptly named element parameter). This is part of the DOM specification, there is no jQuery involved here.
It should be noted though that some browsers fail to implement the full DOM specs; to make it work in IE as well, you’ll have to “borrow” the .forEach() method from the Array prototype first:
// current is a single element
var current = document.querySelector('#current')
// imgs is a node list containing all img elements
// that match your query selector ('.imgs img')
var imgs = document.querySelectorAll('.imgs img')
imgs.forEach(function (element) {
// To each element in the node list, you add a
// 'click' event listener
element.addEventListener('click', function (e) {
// You assign the event target's .src to
// the current .src; and the event target
// is the element that got actually clicked.
// In your case it will always be so that
// e.target === element
current.src = e.target.src
})
})