Advertisement
NoderCoder

Untitled

Apr 8th, 2020
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let mainbody = document.querySelector("body");
  2.  
  3. let parentDiv = document.createElement("div");
  4. parentDiv.setAttribute("id","mainWrapper");
  5. parentDiv.style.display = "grid";
  6. parentDiv.style.gridTemplateColumns = "repeat(16,1fr)"
  7. parentDiv.style.border = "1px solid red";
  8. parentDiv.style.fontSize = "10px";
  9. parentDiv.style.backgroundColor = "white";
  10. mainbody.appendChild(parentDiv);
  11.  
  12. // inner Child Divs
  13.  
  14. for (let y = 1; y <= 16; y++) {
  15.     for (var x = 1; x <= 16; x++) {
  16.         let childDiv = document.createElement("div");
  17.         childDiv.classList.add("old-background");
  18.         childDiv.setAttribute("id", ("R" + y + "C" + x));
  19.         childDiv.textContent = "R" + y + "C" + x;
  20.         childDiv.setAttribute("style", "height:50px;width:auto");
  21.         childDiv.style.border = "1px solid black";
  22.         parentDiv.appendChild(childDiv);
  23.     }
  24. }
  25.  
  26. // event listners
  27.  
  28. const cDivs = document.querySelectorAll('.old-background');
  29. cDivs.forEach(cD => cD.addEventListener('mouseover',changeColor1));
  30.  
  31. function changeColor1() {
  32.     console.log(this.id);
  33.     document.this.style.backgroundColor = "pink";
  34.    
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement