Created
October 1, 2018 16:09
-
-
Save manekinekko/49e2b996660560b80b189e89cf89d43f 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 elements = document.querySelectorAll('button'); | |
const len = elements.length; // 8 par exemple | |
for(let i=0; i<len; i+=1){ | |
(function(n){ | |
elements[n].addEventListener('click', function(){ | |
alert(n+1) | |
}, false); | |
})(i); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment