Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. //error-version
  2.  
  3. //html
  4. button{$}*4
  5. .output
  6.  
  7. //js
  8. var buttons = document.querySelectorAll('button')
  9. var output = document.querySelctor('.output')
  10.  
  11. for(var i=0; i< buttons.length; i++){
  12. buttons[i].addEventListener('click', function(){
  13. ouput.innerText = buttons[i].innerText
  14. })
  15. }
  16.  
  17. //console
  18. Uncaught TypeError: Cannot read property 'innerText' of undefined
  19.  
  20. //es6-version
  21. ...
  22. //js
  23. var buttons = document.querySelectorAll('button')
  24. var output = document.querySelctor('.output')
  25.  
  26. for(let i=0; i< buttons.length; i++){
  27. buttons[i].addEventListener('click', function(){
  28. ouput.innerText = buttons[i].innerText
  29. })
  30. }
  31.  
  32. //babel-output
  33.  
  34. var _loop = function (i) {
  35. buttons[i].addEventListener('click', function () {
  36. output.innerText = buttons[i].innerText
  37. })
  38. }
  39. for (var i = 0; i < buttons.length; i++) {
  40. _loop(i)
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement