Last active
November 5, 2017 20:03
-
-
Save softwarespot/fec305ef1d205498e86406126be9f587 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const displayImgEl = document.querySelector('main div img'); | |
// Bind an "onImgClick" function to all image elements found | |
const els = document.querySelectorAll('.thumb-bar img'); | |
els.forEach((el => el.addEventListener('click', onImgClick)); | |
function onImgClick(event) { | |
// Get the current element which was clicked. | |
// Could also use event.target too | |
const el = event.currentTarget; | |
// Get the image "src" attribute value | |
const src = el.getAttribute('src'); | |
// Set the display element "src" attribute, | |
// to use the src value of the element selected | |
displayImgEl.setAttribute('src', src); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment