Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function createSquareDivs(){
  2.     const container = document.querySelector("#container");
  3.  
  4.     for (let i = 0; i < 16; i++){
  5.         let div = document.createElement("div"); // first div to contain a row
  6.  
  7.         for (let j = 0; j < 16; j++){
  8.             let div2 = document.createElement("div"); // second div to fill the columns
  9.             div2.style.width = "30px";
  10.             div2.style.height = "30px";
  11.             div2.style.display = "inline-block";
  12.             div2.addEventListener("mouseenter", mouseEnterDiv(div2)) // Event isn't added
  13.             div.appendChild(div2);
  14.            
  15.         }
  16.         container.appendChild(div);
  17.     }
  18. }
  19.  
  20. function mouseEnterDiv(div){
  21.     let red = Math.floor(Math.random() * 256);
  22.     let green = Math.floor(Math.random() * 256);
  23.     let blue = Math.floor(Math.random() * 256);
  24.     div.style.background = `rgb("${red}","${green}","${blue}")`;
  25. }
  26.  
  27. createSquareDivs()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement