Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //error-version
- //html
- button{$}*4
- .output
- //js
- var buttons = document.querySelectorAll('button')
- var output = document.querySelctor('.output')
- for(var i=0; i< buttons.length; i++){
- buttons[i].addEventListener('click', function(){
- ouput.innerText = buttons[i].innerText
- })
- }
- //console
- Uncaught TypeError: Cannot read property 'innerText' of undefined
- //es6-version
- ...
- //js
- var buttons = document.querySelectorAll('button')
- var output = document.querySelctor('.output')
- for(let i=0; i< buttons.length; i++){
- buttons[i].addEventListener('click', function(){
- ouput.innerText = buttons[i].innerText
- })
- }
- //babel-output
- var _loop = function (i) {
- buttons[i].addEventListener('click', function () {
- output.innerText = buttons[i].innerText
- })
- }
- for (var i = 0; i < buttons.length; i++) {
- _loop(i)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement