Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function createSquareDivs(){
- const container = document.querySelector("#container");
- for (let i = 0; i < 16; i++){
- let div = document.createElement("div"); // first div to contain a row
- for (let j = 0; j < 16; j++){
- let div2 = document.createElement("div"); // second div to fill the columns
- div2.style.width = "30px";
- div2.style.height = "30px";
- div2.style.display = "inline-block";
- div2.addEventListener("mouseenter", mouseEnterDiv(div2)) // Event isn't added
- div.appendChild(div2);
- }
- container.appendChild(div);
- }
- }
- function mouseEnterDiv(div){
- let red = Math.floor(Math.random() * 256);
- let green = Math.floor(Math.random() * 256);
- let blue = Math.floor(Math.random() * 256);
- div.style.background = `rgb("${red}","${green}","${blue}")`;
- }
- createSquareDivs()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement