Advertisement
Guest User

Untitled

a guest
Aug 4th, 2015
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. <html>
  2.  
  3. <head>
  4. <style>
  5. .container {
  6. width: 160px;
  7. height: 160px;
  8. background-color: grey;
  9. }
  10. .container .cell {
  11. float: left;
  12. width: 40px;
  13. height: 40px;
  14. background-color: lightblue;
  15. }
  16. #go {
  17. width: 50px;
  18. height: 50px;
  19. border-radius: calc(50px/2);
  20. background-color: green;
  21. margin-bottom: 5em;
  22. }
  23. </style>
  24. </head>
  25. <body>
  26. <div id='go'></div>
  27. <div class='container'>
  28. </div>
  29. </body>
  30. <script>
  31. var numberArray = [
  32. 0,
  33. 1,
  34. 0,
  35. 1,
  36. 0,
  37. 1,
  38. 0,
  39. 1,
  40. 0,
  41. 1,
  42. 0,
  43. 1,
  44. 0,
  45. 1,
  46. 0,
  47. 1,
  48. ]
  49.  
  50. numberArray.forEach(function(n, i) {
  51. var container = document.querySelector('.container');
  52. var cell = document.createElement('div');
  53. cell.classList.add('cell');
  54. cell.innerHTML = numberArray[i];
  55. container.appendChild(cell);
  56. });
  57.  
  58. var go = document.getElementById('go');
  59. go.addEventListener('click', function(e) {
  60. var cells = Array.prototype.slice.call(document.querySelectorAll('.cell'));
  61. cells.forEach(function(c) {
  62. c.style.backgroundColor = 'red';
  63. })
  64. });
  65. </script>
  66.  
  67. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement